#include //#include using namespace std; //using namespace atcoder; using ll = long long; //using mint = modint998244353; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); int N, x, y, ans=1e9; cin >> N; queue> que; vector dist(1000, vector(1000, 1e9)); for (int i=0; i> x >> y; dist[x][y] = 0; que.push({x, y}); } auto f=[&](int i, int j){ return 0<=i && i<1000 && 0<=j && j<1000; }; int dx[4] = {1,0,-1,0}; int dy[4] = {0,1,0,-1}; while(!que.empty()){ tie(x, y) = que.front(); que.pop(); for (int i=0; i<4; i++){ int nx=x+dx[i], ny=y+dy[i]; if (f(nx, ny) && dist[nx][ny] == 1e9){ dist[nx][ny] = dist[x][y]+1; que.push({nx, ny}); } } } cin >> N; for (int i=0; i> x >> y; ans = min(ans, dist[x][y]); } cout << ans << endl; return 0; }