Idiom:
Blessing in disguise
At first, but later turns out to be good.
Example: Losing that job was a blessing in
disguise, because it led me to a better
opportunity.