import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines a,b,c,d = map(int,read().split()) x = max(a,b) if all((a == b, c == d, c <= a, d <= b)): x -= 1 print(x)