r, c = map(int, input().split()) y1, x1 = map(int, input().split()) y2, x2 = map(int, input().split()) print(abs(y1 - y2) + abs(x1 - x2))