#include #include int main(){ int N; std::cin >> N; long min_flow = 2 * std::pow(10, 8); for(int i = 0; i < N; i++){ long A,B,C,D,E; std::cin >> A >> B >> C >> D >> E; long x_1 = std::min(E, D); long x_2 = D - x_1; long x_3 = A + std::min(C, x_2); long x_4 = x_1 + std::min(B, x_3); long y_1 = std::min(A, B); long y_2 = A - y_1; long y_3 = D + std::min(C, y_2); long y_4 = y_1 + std::min(E, y_3); min_flow = std::min(min_flow, std::max(x_4, y_4)); } std::cout << min_flow << std::endl; return 0; }