#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; const long long MOD = 1000000007; typedef long long ll; int main(int argc, char *argv[]) { int n; cin >> n; int a[50], b[50]; int in = 0, out = 0; rep(i, n - 1) { cin >> a[i + 1] >> b[i + 1]; in += a[i + 1]; out += b[i + 1]; } if (in < out) { int tmp; tmp = in; in = out; out = tmp; rep(i, n) { tmp = a[i]; a[i] = b[i]; b[i] = tmp; } } int l = 0, r = 10000000; while (r - l > 1) { int med = (l + r) / 2; a[0] = med; b[0] = in - out + med; bool flag = true; rep(i, n) { if (a[i] > in + med - b[i]) { flag = false; break; } if (b[i] > in + med - a[i]) { flag = false; break; } } if (flag) l = med; else r = med; } cout << r << endl; return 0; }