Right only
Dragon Gorynych finds himself trapped in a labyrinth and wants to escape as quickly as possible. However, after consuming kefir yesterday, his left head isn't functioning well. As a result, Dragon Gorynych can only turn right and move straight; he cannot turn left or make a U-turn. Your task is to help Dragon Gorynych find the shortest path to the labyrinth's exit.
Input
The first line contains the integers r and c (4 ≤ r, c ≤ 20), representing the number of rows and columns in the labyrinth map. Each of the following r lines contains c characters that describe the map. The character S indicates Dragon Gorynych's starting position, F marks the exit, and X represents a wall. Spaces indicate passable cells. The labyrinth is guaranteed to be enclosed by walls. Before starting, Dragon Gorynych can face any of the 4 directions (up, down, left, or right).
Output
Output a single number representing the distance Dragon Gorynych must travel to reach the exit. It is guaranteed that he will always be able to find a way out of the labyrinth.