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