Punishment is harm

Bentham said that “punishment is harm. Therefore punishment can only be justified if it prevents greater evil than it produces.”
Do you agree with this? Why or why not?
What if if doesn’t prevent greater evil?