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