Your sensors must be able to detect an intersection.
Your controller must count intersections until it reaches the one which you enter just before a run.
You want it to make a right turn, followed by a left turn at the next intersection. Then it should make no more turns after that.
That's the easiest way.
Or are you supposed to have your robot generate a map in its memory while exploring? And have it turn around when it reaches a dead end, and learn its coordinates? Etc.