x, y = map(int, input().split()) bx, by = map(int, input().split()) if bx < x and x == y and bx == by: print(x + 1) else: print(min(x, y) + abs(x - y))