I'll be honest I'm not sure of the formal equations one would use to solve this however I'll give you what I think to be a solution with my reasoning.
The system starts with 2000 j of internal energy and has 1000 j of heat energy enter the system. After this 500 j of energy leaves the system in the form of work done by the piston. So we get...
2000j +1000j - 500j = 2500 j
final energy in system is 2500 j