#include <iostream> #include <vector> #include <string> #include <cmath> #include <iomanip> #include <algorithm> using namespace std; using ll = long long; constexpr ll M = 1e9+7; int main() { int aw, ab, bw, bb; cin >> aw >> ab >> bw >> bb; int c,d; cin >> c >> d; int r = min(aw, aw+(ab-c)); cout << r + min(bw+aw-r, d) << endl; }