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