necessary evil

noun
Graduate
1

An unfavorable thing that must be done or accepted, especially because the available alternative courses of action or inaction would be worse.