R,C = map(int,input().split())

sy,sx = map(int,input().split())
gy,gx = map(int,input().split())

print (abs(sy-gy) + abs(sx-gx))