#include <iostream>
#include <sstream>
#include <math.h>
#include <stack>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <cstdio>
#include <vector>
using namespace std;

#define INF (1 << 30)
#define INFLL (1LL << 60)

int main() {
	int aw,ab,bw,bb,e,f;
	cin >> aw >> ab >> bw >> bb >> e >> f;
	if(ab > e){
		ab -= e;
		bb += e;
	}else{
		bb += ab;
		aw -= e-ab;
		bw += e-ab;
		ab = 0;
	}

	if(bw > f){
		aw += f;
	}else{
		aw += bw;
	}
	cout << aw << endl;
	return 0;
}