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