aw, ab, bw, bb, c, d = io.read("*n","*n","*n","*n","*n","*n") mv1b = math.min(ab, c) mv1w = c - mv1b aw, ab, bw, bb = aw - mv1w, ab - mv1b, bw + mv1w, bb + mv1b mv2w = math.min(bw, d) print(aw + mv2w)