ways = [(0, 1), (0, -1), (1, 0), (-1, 0)] H, W = map(int, input().split()) S_i, S_j = map(lambda x: int(x) - 1, input().split()) G_i, G_j = map(lambda x: int(x) - 1, input().split()) grid = [[0 for _ in range(W)] for _ in range(H)] stack = [(0, S_i, S_j)] # 0: 行きがけ, 1: 戻りがけ ans = 0 while stack: state, now_i, now_j = stack.pop() if now_i == G_i and now_j == G_j: ans += state continue if state == 0: grid[now_i][now_j] += 1 for di, dj in ways: next_i, next_j = now_i + di, now_j + dj if 0 <= next_i < H and 0 <= next_j < W: grid[next_i][next_j] += 1 for di, dj in ways: next_i, next_j = now_i + di, now_j + dj if not (0 <= next_i < H and 0 <= next_j < W): continue if grid[next_i][next_j] <= 1: stack.append((1, next_i, next_j)) stack.append((0, next_i, next_j)) else: grid[now_i][now_j] -= 1 for di, dj in ways: next_i, next_j = now_i + di, now_j + dj if 0 <= next_i < H and 0 <= next_j < W: grid[next_i][next_j] -= 1 print(ans)