#include <stdio.h>
int main() {
int n, m;
while(scanf("%d%d", &n, &m) != EOF) {
int maze[10][10];
char g_data[100][2] = {0};
// 先将迷宫读取到maze中
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++){
scanf("%d", &maze[i][j]);
}
}
// 然后我们定义一些参数方便后面的DFS
int row, col, idx = 0;
while (idx >= 0) {
row = g_data[idx][0];
col = g_data[idx][1];
if((row == n - 1) && (col == m - 1)) break;
maze[row][col] = 1;
// 如果下面可以走,并且还没有被访问过(或者本来就是路)
if(((row + 1) < n) && (maze[row + 1][col] == 0)) {
// 我们下次可以访问这个节点
g_data[++idx][0] = row + 1;
g_data[idx][1] = col;
}
// 如果可以往上走,别忘了等于0的情况也是可以走的
else if(((row - 1) >= 0) && (maze[row - 1][col] == 0)) {
g_data[++idx][0] = row - 1;
g_data[idx][1] = col;
}
else if(((col - 1) >= 0) && (maze[row][col - 1] == 0)) {
g_data[++idx][0] = row;
g_data[idx][1] = col - 1;
}
else if(((col + 1) < m) && (maze[row][col + 1] == 0)) {
g_data[++idx][0] = row;
g_data[idx][1] = col + 1;
}
else {
idx--;
}
}
for(int i = 0; i <= idx; i++) {
printf("(%d,%d)\n", g_data[i][0], g_data[i][1]);
}
}
return 0;
}