#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, M;
cin >> N >> M;
pair<int, int> p;
vector<vector<int>> v(N, vector<int>(M));
for (int i = 0; i < N;i++) {
for (int j = 0;j < M;j++) {
cin >> v[i][j];
if (v[i][j] == 2) p = { i, j };
}
}
queue<pair<int, int>> q;
q.push(p);
v[p.first][p.second] = 0;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
int x, y;
while (!q.empty()) {
p = q.front();
q.pop();
x = p.first;
y = p.second;
}
return 0;
}