H,W = map(int, input().split()) A = [input() for _ in range(H)] D = [[{} for _ in range(W)] for _ in range(H)] D[0][0][1] = 1 for n in range(H+W-2): i = 0 j = n-i while j >= 0: if (0<=i