R,C = map(int,input().split()) s = tuple(map(int,input().split())) g = tuple(map(int,input().split())) ans = abs(s[0]-g[0])+abs(s[1]-g[1]) print(ans)