aw, ab = map(int, input().split()) bw, bb = map(int, input().split()) c, d = map(int, input().split()) num = aw - max(0, c - ab) bw += max(0, c - ab) num += min(d, bw) print(num)