In a magical country, the country is a two-dimensional matrix of
lines
rows, the
representative can walk road,
represent a wall, can not pass. little F to set off for the company
to work from home
every day, in this magical land, every second of the speed of walking with the real life is not the same: 1、if one person always in one direction is one second can walk one or two square , of course, You can't go through a wall while going straight through two blocks.
2、If you want to turn, you can only go one square in one second.
Now little F wants to know what is the minimum time from home to the company? If there is no feasible way to output -1. At begining, it is considered to go straight in every direction from home.
We make sure that the data has one and only one S and E.
输入描述:
The first line contains two integers
represents the length and width of the matrix
Then
lines of characters,
for the road,
for the wall,
for the home of little F, and
for the location of the company
输出描述:
Print one integer — the minimum time from home to the company
示例1
输入
复制
5 6
..SE..
...*..
...*..
...*..
......