Does plan b work?

I heard some people still got pregnant on it. But I took the pill a couple hours after sex and idk if I was ovulating or not. Am I safe?