The Forest
题号:NC14325
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
64bit IO Format: %lld

题目描述

You are a brave man.You will go through the Bad Forest.




This Bad Forest has n rows and m columns.
There are a lot of bad person and trees in this forest.
The bad person will move, and the speed is the same as you. 
If you reach a point, this point has a bad person, then you need to battle with a bad people.
The number of the war times equal to the number of bad person. 
You would like to leave the forest. 
Ask you what is the minimum number of the war.

输入描述:

The first line consists of two integers: r and m (1≤n,m≤1000).
The next n rows is the Forest map .
'T' is a tree.
'S' is an empty cell, and your starting position.
'E' is an empty cell, and where the exit is located.
A digit (0-9): Digital X represents the number of bad person in this cell

输出描述:

The output is a minimum figure that you can get out of the forest.
示例1

输入

复制
5 7
000E0T3
T0TT0T0
010T0T0
2T0T0T0
0T0S000
1 4
SE23

输出

复制
3
2