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