#include using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define pb push_back typedef long long ll; typedef pair pii; typedef vector vi; int main() { cin.tie(0)->sync_with_stdio(0); vector need(3), have(3); for(int i = 0; i < 3; i++) cin >> need[i]; for(int i = 0; i < 3; i++) cin >> have[i]; int red = max(0, need[0]-have[0]); int green = max(0, need[1]-have[1]); int blue = max(0, need[2]-have[2]); int rg, gb; cin >> rg >> gb; int ans = 1000000; bool found = false; for(int i = 0; i <= rg; i++) { for(int j = 0; j <= gb; j++) { int RG = i; int GB = j; RG -= red; GB -= blue; if(RG >= 0 && GB >= 0 && RG+GB >= green) { ans = min(ans, i+j); found = true; } } } if(!found) ans = -1; cout << ans << "\n"; }