#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSAKewogICAgaW50IG4sIGEsIGIsIGMsIHgsIHksIHo7CiAgICBjaW4gPj4gbiA+PiBhID4+IGIgPj4gYyA+PiB4ID4+IHkgPj4gejsKICAgIGlmICh4ICsgeSArIHogPT0gMCkgewogICAgICAgIGNvdXQgPDwgMDsKICAgIH0KICAgIGVsc2UgewogICAgICAgIGNvdXQgPDwgKHggKyB5ICsgeikgLSAoYSArIGIgKyBjIC0gbik7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==