#include using namespace std; using ll = long long; using ull = unsigned long long; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int res = 500000000; for(int i = 0; i < n; ++i) { int a, b, c, d, e; cin >> a >> b >> c >> d >> e; int tp = 0; tp += min(a, b); a -= min(a, b); b -= min(a, b); tp += min(d, e); d -= min(d, e); e -= min(d, e); tp += max(min({a, c, e}), min({d, c, b})); res = min(res, tp); } cout << res << '\n'; return 0; }