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

c -= min(ab , c)
aw -= c
bw += c
aw += min(d , bw)
print(aw)