// Arup Guha
// 6/5/2026
// Solution to Kattis Problem: Art Installation
// https://open.kattis.com/problems/artinstallation

using namespace std;
#include <bits/stdc++.h>

int main() {

    // Easiest problem, just multiply the two input numbers.
    int r, g, b, hR, hG, hB;

    cin >> r >> g >> b >> hR >> hG >> hB;
    r = max(0, r-hR);
    g = max(0, g-hG);
    b = max(0, b-hB);

    // If you can do it, this is the result.
    int res = r + g + b;

    int rg, gb;
    cin >> rg >> gb;

    // Only way to cover these.
    if (rg < r)
        res = -1;

    // Only way to cover these.
    else if (gb < b)
        res = -1;

    // Greedy cover.
    else {

        // Cover R and B.
        rg -= r;
        gb -= b;

        // If we don't have enough of both, we can't cover the green.
        if (rg+gb < g) res = -1;
    }

    cout << res << endl;
    return 0;
}
