Measurement of the CP-violating phase β in B0→J/ψπ+π- decays and limits on penguin effects