m, n = list(map(intinput().split()))

maze = []

for _  in range(m):

    maze.append(list(map(intinput().split())))

out = []

def out_add(ij):

    if (i,j) not in out:

        out.append((i,j))

def out_del():

    del out[-1]

def move(ij):

    if i==m-1 and j==n-1:

        out_add(i,j)

        return

    if i-1>=0 and maze[i-1][j]==0:

        out_add(i,j)

        maze[i][j] = 2

        move(i-1, j)

    elif i+1<m and maze[i+1][j]==0:

        out_add(i,j)

        maze[i][j] = 2

        move(i+1, j)

    elif j-1>=0 and maze[i][j-1]==0:

        out_add(i,j)

        maze[i][j] = 2

        move(i, j-1)

    elif j+1<n and maze[i][j+1]==0:

        out_add(i,j)

        maze[i][j] = 2

        move(i, j+1)

    else:

        out_add(i,j)

        maze[i][j] = 1

        back(i,j)

def back(i,j):

    out_del()

    if i-1>=0 and maze[i-1][j]==2:

        move(i-1, j)

    elif i+1<m and maze[i+1][j]==2:

        move(i+1, j)

    elif j-1>=0 and maze[i][j-1]==2:

        move(i, j-1)

    elif j+1<n and maze[i][j+1]==2:

        move(i, j+1)

move(0,0)

for i in out:

    print('(' + str(i[0]) + ',' + str(i[1]) + ')')