#include<bits/stdc++.h>
using namespace std;
const int N = 1000 + 5;
const int M = 50000 + 5;
int c = 0;
bool f = 0;
int n, m;
int sx, sy;
int fx, fy;
int mp[N][N];
bool vis[N][N];
int dx[4] = {-1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int ddx[M], ddy[M];
void dfs(int nx,int ny){
if (nx == fx && ny == fy) {
f = 1;
cout<<"(" << sx <<","<< sy << ")" << "->";
for(int i = 0; i < c; i ++)
cout<< "(" << ddx[i] <<","<< ddy[i] << ")" <<"->";
cout<<"(" << fx <<","<< fy << ")" << endl;
return;
}
for(int i = 0; i < 4; i ++){
int vx = nx + dx[i], vy = ny + dy[i];
if(vx <= 0 || vx > n || vy <= 0 || vy > m)continue;
if(vis[vx][vy] == 1 || mp[vx][vy] == 0)continue;
vis[vx][vy] = 1;
ddx[c] = vx;
ddy[c] = vy;
c ++;
dfs(vx, vy);
vis[vx][vy] = 0;
c --;
}
}
int main(){
cin>> n >> m;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j++)
cin>> mp[i][j];
cin >> sx >> sy >> fx >> fy;
vis[sx][sy] = 1;
dfs(sx, sy);
if(f == 0) cout<< "-1";
return 0;
}