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) x = min(ab, c) ab -= x bb += x aw -= c - x bw += c - x # print(ab, aw, bb, bw) # D # print(d) y = min(bw, d) bw -= y aw += y bb -= d - y bw += d - y # print(ab, aw, bb, bw) print(aw)