def bfs() :
x = 0
y = 0
queue = [[0,0]]
visited = [[0,0]]
dic = {(0,0):0}
ans = []
while queue:
[x, y] = queue.pop(0)
for dirrect in dirrection:
if 0<=x+dirrect[0]<n and 0<=y+dirrect[1]<m and [x+dirrect[0],y+dirrect[1]] not in visited:
if map_[x+dirrect[0]][y+dirrect[1]] != 2:
dic[(x+dirrect[0],y+dirrect[1])] = dic[(x,y)] + 1
visited.append([x+dirrect[0],y+dirrect[1]])
queue.append([x+dirrect[0],y+dirrect[1]])
if map_[x+dirrect[0]][y+dirrect[1]] == 1:
ans.append(dic[(x+dirrect[0],y+dirrect[1])])
else:
visited.append([x+dirrect[0],y+dirrect[1]])
return ans
dirrection = ((1,0), (0,1), (-1,0), (0,-1))
n,m = map(int,input().split())
map_ = []
for i in range (n):
map_.append(list(map(int,input().split())))
ans = bfs()
if ans:
for i in ans:
print(i)
else:
print("嘉油!")