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