x, y = map(int, input().split()) x2, y2 = map(int, input().split()) d = max(x, y) on_path = (x2 <= x and y2 <= y) and (max(x2, y2) + max(x - x2, y - y2) == d) if on_path: if x == y and x2 == y2: print(d + 1) else: print(d) else: print(d)