import sys from collections import deque input = sys.stdin.readline n, m = map(int, input().split()) q = deque() miro = [list(map(int,input().strip())) for _ in range(n)] visited = [[0]*m for _ in range(n)] dx, dy = [-1,1,0,0],[0,0,-1,1] def bfs(): while q: x, y = q.popleft() if x == n - 1 and y == m - 1: print(visited[x][y]) break for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0