毒薬変じて薬となる(どくやくへんじてくすりとなる)

Japanese vocabulary

Meaning: what is bad for you might end up good; poison changes into medicine

See it used in real works