a, b, c, d = map(int, input().split())
print(min(min(a, b), min(c - a, d - b)))

40e37e2a0047473bfa8aa6c577e509c7226f2a8b
<mask token>

<mask token>
print(min(min(a, b), min(c - a, d - b)))

a, b, c, d = map(int, input().split())
print(min(min(a, b), min(c - a, d - b)))
