#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct node{
ll x,y,step;
};
ll n,sx,sy,ex,ey;
bool vis[1005][1005];
ll dx[8] = {-1,1,-2,2,-2,2,-1,1};
ll dy[8] = {-2,-2,-1,-1,1,1,2,2};
void bfs(){
queue<node> q;
q.push({sx,sy,0});
vis[sx][sy] = 1;
while(!q.empty()){
node now = q.front();
q.pop();
if(now.x == ex && now.y == ey){
cout << now.step;
return ;
}
for(ll i = 0;i <= 7;i++){
ll xx = now.x + dx[i];
ll yy = now.y + dy[i];
if(xx >= 0 && xx < n && yy >= 0 && yy < n && !vis[xx][yy]){
vis[xx][yy] = 1;
q.push({xx,yy,now.step + 1});
}
}
}
}
int main(){
cin >> n;
cin >> sx >> sy >> ex >> ey;
bfs();
return 0;
}