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