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