#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using i64 = int64_t; i64 n; vector a, b; int main() { cin >> n; a.resize(n); b.resize(n); i64 sa = 0, sb = 0; for (int i = 0; i < n - 1; ++i) { cin >> a[i] >> b[i]; sa += a[i]; sb += b[i]; } i64 x = 0; for (int i = 0; i < n - 1; ++i) { x = max(x, max(sa, sb) - (sa - a[i]) - (sb - b[i])); } i64 ans = min(sa, sb) + 1; cout << ans - x << endl; return 0; }