#include <stdio.h>
int n, a, b, c, d;
int arr[1001][1001]={};
int q[2][1000001]={};
int px, py, s=0, e=0;
int sum=0;
int flag=0;
void push(int x, int y)
{
if (x>n || y>n || x<1 || y<1 || arr[x][y]!=0)
{
return;
}
if (x==c && y==d)
{
flag=1;
}
q[0][e]=x;
q[1][e]=y;
e++;
}
void pop()
{
s++;
px = q[0][s-1];
py = q[1][s-1];
}
int main()
{
scanf("%d", &n);
scanf("%d %d", &a, &b);
scanf("%d %d", &c, &d);
arr[a][b]=1;
arr[c][d]=2;
q[0][e]=a;
q[1][e]=b;
while (s!=e)
{
int k = e;
for (int i=s ; i<k ; i++)
{
pop();
push (px-1, py-2);
push (px-2, py-1);
push (px-2, py+1);
push (px-1, py+1);
push (px+1, py-2);
push (px+2, py-1);
push (px+2, py+1);
push (px+1, py+2);
if(flag==1)
{
printf("%d",sum);
return 0;
}
}
}
}
// />---フ
// / _ _|
// / ミ_c_ノ
// / |
// / \ /
// │ | | |
// / | | |
// ( ̄/__\_)__)
// | \
// \_二二二)



