when to take plan b?

If my boyfriend cums inside of me , how long do I have to take the plan b pill? Do I take it right after or wait a couple of hours?