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