import sys
from maze import parse_maze
if len(sys.argv) == 2:
m = parse_maze(open(sys.argv[1], 'r').read())
else:
m = parse_maze(sys.stdin.read())
print m.solve()