r, c = map(int, input().split()) sy, gy = map(int, input().split()) sx, gx = map(int, input().split()) print(abs(sy-gy) + abs(sx-gx))