aw, ab = map(int, input().split()) bw, bb = map(int, input().split()) c, d = map(int, input().split()) atob_w = 0 if c <= ab else c - ab btoa_w = min(d, bw + atob_w) print(aw - atob_w + btoa_w)