#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;
ll n,x,y,x2,y2,used[30][30];
int main() {
queue<pair<int,int>>q;
vector<pair<int,int>>v;
v.push_back({2,-1});
v.push_back({2,1});
v.push_back({1,-2});
v.push_back({1,2});
v.push_back({-2,-1});
v.push_back({-2,1});
v.push_back({-1,-2});
v.push_back({-1,2});
cin>>n>>x>>y>>x2>>y2;
q.push({x,y});
used[x][y]=1;
while(!q.empty()){
for(int i=0;i<8;i++){
pair<int,int>t=q.front();
if(t.F+v[i].F>=1&&t.F+v[i].F<=n&&t.S+v[i].S>=1&&t.S+v[i].S<=n&&used[t.F+v[i].F][t.S+v[i].S]==0){
q.push({t.F+v[i].F,t.S+v[i].S});
used[t.F+v[i].F][t.S+v[i].S]=used[t.F][t.S]+1;
}
}
q.pop();
}
cout<<used[x2][y2]-1;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgRiBmaXJzdAojZGVmaW5lIFMgc2Vjb25kCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogICAgbGwgbix4LHkseDIseTIsdXNlZFszMF1bMzBdOwppbnQgbWFpbigpIHsKICAgIHF1ZXVlPHBhaXI8aW50LGludD4+cTsKICAgIHZlY3RvcjxwYWlyPGludCxpbnQ+PnY7CiAgICB2LnB1c2hfYmFjayh7MiwtMX0pOwogICAgdi5wdXNoX2JhY2soezIsMX0pOwogICAgdi5wdXNoX2JhY2soezEsLTJ9KTsKICAgIHYucHVzaF9iYWNrKHsxLDJ9KTsKICAgIHYucHVzaF9iYWNrKHstMiwtMX0pOwogICAgdi5wdXNoX2JhY2soey0yLDF9KTsKICAgIHYucHVzaF9iYWNrKHstMSwtMn0pOwogICAgdi5wdXNoX2JhY2soey0xLDJ9KTsKICAgIAogICAgY2luPj5uPj54Pj55Pj54Mj4+eTI7CiAgICAKICAgIHEucHVzaCh7eCx5fSk7CiAgICB1c2VkW3hdW3ld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