necessary evil

US /ˈnɛs.əˌser.i ˈiː.vəl/
UK /ˈnɛs.əˌser.i ˈiː.vəl/
"necessary evil" picture
1.

something unpleasant that must be accepted or done in order to achieve a particular result

:
Paying taxes is a necessary evil if we want public services.
For some, working long hours is a necessary evil to achieve financial stability.