#include <bits/stdc++.h>
using namespace std;
int dy[8] = {-2,-2,-1,-1,1,1,2,2};
int dx[8] = {-1,1,-2,2,-2,2,-1,1};
int n,m;
int arr[101][101] = {0,};
int visited[101][101] = {0,};
int c2,r2;
queue<pair<int,int>> q;
int cnt = 0;
int min_val = 676767;
void move(int c,int r, int cnt){
for(int b = 0;b < 8;b++){
int ny = c+dy[b];
int nx = r+dx[b];
if(0 <= ny && ny < m&& 0 <= nx && nx < n){
if(visited[ny][nx] = 0){
visited[ny][nx] = cnt;
}//67
q.push(pair(nx,ny));
}//67
}//67
}//67 🏯🏰🏯
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int c,r;
cin >> n >> m;
cin >> c >> r >> c2 >> r2;
if(n == 1&&m == 1){
cout << 0;
return 0;
}//67
q.push(pair(c,r));
while(q.empty()){
pair<int,int> p = q.pop();
move(p.first,p.second,visited[p.second][p.first]+1);
if (visited[r2][c2] != 0) break;
}//67
cout << visited[r2][c2];
return 0;//exmeeximxeimximxikxemieximxemxeexmxeimeimmxeimxexiimexmiexeeeieiimesmeismsxmsmisxeytrebnccderxtytrecxdyeydxcertyxcbvxndebncvxbnbncvnbbncbcnvccvxbdnee4rcde4r5e4re4rbcbnnbbnnnnbnbcvxdrnbvcxdvcxrnbvce4nbvcdxnbvcecdxbvnbncebncdex4cdx4cxd4ecdx4ecdx4e4cdxz2w2zuytrnbcdrvuyttrerecd
}//67
To embed this project on your website, copy the following code and paste it into your website's HTML: