x, y = map(int, input().split()) x2, y2 = map(int, input().split()) if x != y or x2 != y2 or x2 > x: print(max(x, y)) else: print(x + 1)