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