aw, ab = map(int, input().split())
bw, bb = map(int, input().split())
c, d = map(int, input().split())

if c <= ab:
    ans = aw
    bb += c
else:
    ans = aw - (c - ab)
    bb += ab
    bw += c - ab
if d <= bw:
    ans += d
else:
    ans += bw
print(ans)