#include <iostream>
using namespace std;
int complect(int & b, int & a) {
int com = min(a, b);
a -= com;
b -= com;
return com;
}
int main() {
int a1, a2, a3, b1, b2, b3, c; //c-все возможные комплекты
cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3;
c = 0;
c += complect(a1, b1);
c += complect(a2, b2);
c += complect(b1, a3);
c += complect(a1, b3);
c += complect(a2, b3);
c += complect(a3, b3);
c += complect(b1, a3);
c += complect(b2, a3);
cout << c;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBjb21wbGVjdChpbnQgJiBiLCBpbnQgJiBhKSB7CiAgaW50IGNvbSA9IG1pbihhLCBiKTsKICBhIC09IGNvbTsKICBiIC09IGNvbTsKICByZXR1cm4gY29tOwp9CmludCBtYWluKCkgewogIGludCBhMSwgYTIsIGEzLCBiMSwgYjIsIGIzLCBjOyAvL2Mt0LLRgdC1INCy0L7Qt9C80L7QttC90YvQtSDQutC+0LzQv9C70LXQutGC0YsKICBjaW4gPj4gYTEgPj4gYTIgPj4gYTMgPj4gYjEgPj4gYjIgPj4gYjM7CiAgYyA9IDA7CiAgYyArPSBjb21wbGVjdChhMSwgYjEpOwogIGMgKz0gY29tcGxlY3QoYTIsIGIyKTsKICBjICs9IGNvbXBsZWN0KGIxLCBhMyk7CiAgYyArPSBjb21wbGVjdChhMSwgYjMpOwogIGMgKz0gY29tcGxlY3QoYTIsIGIzKTsKICBjICs9IGNvbXBsZWN0KGEzLCBiMyk7CiAgYyArPSBjb21wbGVjdChiMSwgYTMpOwogIGMgKz0gY29tcGxlY3QoYjIsIGEzKTsKCiAgY291dCA8PCBjOwogIHJldHVybiAwOwp9