aw, ab = map(int, input().split())
bw, bb = map(int, input().split())
c, d = map(int, input().split())
if c > ab:
    d -= c - ab
if d > bw:
    d = bw
print(d+aw)