#D3918. Caterpillar
Caterpillar
Caterpillar
G, a college student living in a certain sky city, has a hornworm, Imotaro. He disciplined Imotaro to eat all the food in order with the shortest number of steps. You, his friend, decided to write a program because he asked me to find out if Imotaro was really disciplined.
Input
H W N area
Input is given in H + 1 lines. The first line contains three integers H, W, N (2 ≤ H ≤ 10, 2 ≤ W ≤ 10, 1 ≤ N ≤ 9). H is the height of the area, W is the width, and N is the number of foods (at this time, 6 + N ≤ H × W always holds).
In each line from the 2nd line to H + 1st line, ´S´, ´1´, 2´,… ´9´, ´a´, ´b´, ´c´, ´d´, ´e´, A W character string consisting of ´ # ´ and ´.´ is written, and each represents the state of each section of the area. In addition, ´S´, ´a´, ´b´, ´c´, ´d´, ´e´ represent the initial state of the hornworm. There is no food or obstacles so that it is covered with the hornworm in the initial state. In addition, the initial position of the hornworm and the position of the food are guaranteed to be entered correctly.
Output
Output the minimum number of steps when the hornworm eats food in order, or -1 if that is not possible.
Examples
Input
5 8 3 #....... #.####2# #.#.3..# #.###### .1Sabcde
Output
14
Input
5 8 3 ....... .####2# .#.3..# .###### .1Sabcde
Output
14
Input
2 6 2 .1.baS .2.cde
Output
7
Input
2 6 2 .1#baS .2.cde
Output
-1
inputFormat
Input
H W N area
Input is given in H + 1 lines. The first line contains three integers H, W, N (2 ≤ H ≤ 10, 2 ≤ W ≤ 10, 1 ≤ N ≤ 9). H is the height of the area, W is the width, and N is the number of foods (at this time, 6 + N ≤ H × W always holds).
In each line from the 2nd line to H + 1st line, ´S´, ´1´, 2´,… ´9´, ´a´, ´b´, ´c´, ´d´, ´e´, A W character string consisting of ´ # ´ and ´.´ is written, and each represents the state of each section of the area. In addition, ´S´, ´a´, ´b´, ´c´, ´d´, ´e´ represent the initial state of the hornworm. There is no food or obstacles so that it is covered with the hornworm in the initial state. In addition, the initial position of the hornworm and the position of the food are guaranteed to be entered correctly.
outputFormat
Output
Output the minimum number of steps when the hornworm eats food in order, or -1 if that is not possible.
Examples
Input
5 8 3 #....... #.####2# #.#.3..# #.###### .1Sabcde
Output
14
Input
5 8 3 ....... .####2# .#.3..# .###### .1Sabcde
Output
14
Input
2 6 2 .1.baS .2.cde
Output
7
Input
2 6 2 .1#baS .2.cde
Output
-1
样例
5 8 3
#.......
#.####2#
#.#.3..#
#.######
.1Sabcde
14