a
a = int(input())
k = list(map(int,input().split()))
t = list(map(int,input().split()))
z = [[2,1],[2,-1],[-2,1],[-2,-1],[1,2],[-1,2],[1,-2],[-1,-2]]
x = []
past = []
k.append(0)
x.append(k)
while 1:
x0 = x[0][0]
x1 = x[0][1]
x2 = x[0][2]
if x0==past[0] and x1 == past[1] and len(past)!= 0:
x.pop(0)
continue
#print(x0,x1,x2,t)
if x[0][0] == t[0] and x[0][1] == t[1]:
print(x[0][2])
break
for i in range(8):
if (x0+z[i][0] <= a and x0+z[i][0] > 0) and (x1+z[i][1] <= a and x1+z[i][1] > 0):
x.append([x0+z[i][0],x1+z[i][1],x2+1])
past = [x0,x1]
x.pop(0)1회 조회




