# Arup Guha
# 10/12/2025
# Solution to 2025 NAQ Problem A: Art Installation

def solve(need, special):

    # Only way to get red...
    if special[0] < need[0]:
        return -1

    # And blue.
    if special[1] < need[2]:
        return -1

    # Fill these as required.
    res = need[0] + need[2]

    # Update what's left.
    special[0] -= need[0];
    special[1] -= need[2];

    # Now we can do either.
    if sum(special) < need[1]:
        return -1

    # Here is our answer.
    return res + need[1]

# Get what we need and what we have.
need = [int(x) for x in input().split()]
have = [int(x) for x in input().split()]

# Update what we need to buy.
for i in range(len(need)):
    need[i] = max(0, need[i]-have[i])

# Get what's available.
special = [int(x) for x in input().split()]

# Ta da!
print(solve(need, special))
