#include <iostream>
using namespace std;

int main() 
{
    int n, a, b, c, x, y, z;
    cin >> n >> a >> b >> c >> x >> y >> z;
    if (x + y + z == 0) {
        cout << 0;
    }
    else {
        cout << (x + y + z) - (a + b + c - n);
    }
    return 0;
}