#include using namespace std; int main() { int n; int maxship = INT32_MAX; int tmpship; int a, b, c, d, e, tmpb, tmpe; cin >> n; for ( int i = 0; i < n; i++ ){ cin >> a >> b >> c >> d >> e; tmpship = 0; tmpship += min( a, b ); tmpship += min( d, e ); a -= min ( a, b ); b -= min ( a, b ); d -= min ( d, e ); e -= min ( d, e ); tmpb = min( b, c ); tmpe = min( e, c ); tmpship += min( tmpb, d ); tmpship += min( tmpe, a ); maxship = min ( maxship, tmpship ); } cout << maxship << endl; return 0; }