In an adiabatic irreversible compression process, suppose the pressure $P_{ext}$ compresses the piston and does some work say 50J. (50J of energy is lost by surrounding). Since the pressure $P_{int}$ is less than the $P_{ext}$, the work done by system on surrounding will be -20J(suppose). Negative sign shows that 20J of energy is lost my surrounding. But initially we saw that surrounding lost 50J! How to tackle this discrepancy? I am very confused.