The First Law of Thermodynamics for Open Systems