m, n = list(map(int,input().split())) # m行n列
maze = [list(input().split()) for _ in range(m)] # 不能是int,因为后面对比的是字符
# print(m,n)
# print(maze)
def func(x, y, path):
if x == m -1 and y == n - 1: # 当时出口是打印路径
for i in path:
print(f'({i[0]},{i[1]})')
# 向下移动
# print(x, y, path,maze[x+1][y])
if x + 1 < m and (x+1, y) not in path and maze[x+1][y] == '0': # 当前位置的下方还在地图里,当前路径还没访问过,下方不是墙
func(x+1, y, path + [(x+1, y)])
# 向右移动
if y + 1 < n and (x, y+1) not in path and maze[x][y + 1] == '0':
func(x, y+1, path + [(x, y+1)])
# 向上移动
if x - 1 >= 0 and (x - 1, y) not in path and maze[x-1][y] == '0':
func(x - 1, y, path + [(x - 1, y)])
# 向左移动
if y - 1 >= 0 and (x, y - 1) not in path and maze[x][y - 1] == '0':
func(x, y - 1, path + [(x, y-1)])
func(0, 0, [(0, 0)])