import sys
import collections
import copy
input = sys.stdin.readline
N, M, T = map(int, input().split())
graph = [list(map(str, input().split())) for _ in range(N)]
normal = copy.deepcopy(graph)
sword = copy.deepcopy(graph)
dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]
def bfs_normal(startX, startY):
normal_queue = collections.deque([(0, 0)])
while normal_queue:
x, y = normal_queue.popleft()
for i in range(4):
nx, ny = x+dx[i], y+dy[i]
if 0 <= nx < N and 0 <= ny < M and normal[nx][ny] == '0':
normal_queue.append((nx, ny))
normal[nx][ny] = int(normal[x][y]) + 1
return int(normal[-1][-1])
def bfs_sword(startX, startY, isSword):
visited = [[False] * M for _ in range(N)]
if not isSword:
sword_queue = collections.deque([(0, 0)])
sword[startX][startY] = 1
while sword_queue:
x, y = sword_queue.popleft()
for i in range(4):
nx, ny = x+dx[i], y+dy[i]
if 0 <= nx < N and 0 <= ny < M:
if sword[nx][ny] == '0':
sword_queue.append((nx, ny))
sword[nx][ny] = int(sword[x][y]) + 1
elif sword[nx][ny] == '2':
sword[nx][ny] = int(sword[x][y]) + 1
return bfs_sword(nx, ny, True)
else:
sword_queue = collections.deque([(startX, startY)])
visited[startX][startY] = True
while sword_queue:
x, y = sword_queue.popleft()
for i in range(4):
nx, ny = x+dx[i], y+dy[i]
if 0 <= nx < N and 0 <= ny < M:
if not visited[nx][ny]:
sword_queue.append((nx, ny))
sword[nx][ny] = int(sword[x][y]) + 1
visited[nx][ny] = True
return int(sword[-1][-1])
normal_distance = bfs_normal(0, 0)
sword_distance = bfs_sword(0, 0, False)
if normal_distance and sword_distance:
answer = min(normal_distance, sword_distance-1)
elif sword_distance:
answer = sword_distance-1
else:
answer = normal_distance
if answer > T or (not normal_distance and not sword_distance):
print('Fail')
else:
print(answer)