#T116. 走出迷宫

走出迷宫

Description

When you stand in a maze, the intricate paths often make you lose your sense of direction. If you can obtain the map of the maze, things will become much simpler.
Assume you have acquired the blueprint of an n*m maze, please find the shortest path from the starting point to the exit.

Input Format

The first line contains two integers n and m (1 ≤ n, m ≤ 100), representing the number of rows and columns of the maze.
The next n lines each contain a string of length m, describing the layout of the entire maze.
The character '.' represents an open space, '#' represents a wall, 'S' represents the starting point, and 'T' represents the exit.

Output Format

Output the minimum number of steps required to travel from the starting point to the exit.

3 3
S#T
.#.
...


6