# yukicoder No.208 王将 x, y = map(int, input().split()) x2, y2 = map(int, input().split()) # 対角線上で邪魔してるときだけ一手増える if x2 == y2 and x == y and x - x2 > 0: print(x + 1) else: # それ以外のときは歩兵を避けて最短でいける print(max(x,y))