#include const int NMAX = 40; int A[NMAX]; int B[NMAX]; int main() { int N; std::cin >> N; int in = 0; int out = 0; for (int i = 1; i < N; ++i) { std::cin >> A[i] >> B[i]; in += A[i]; out += B[i]; } int mi = std::max(0, out - in); int ma = std::min(in, out); for (int i = 1; i < N; ++i) { mi = std::max(mi, B[i] - in + A[i]); mi = std::max(mi, A[i] - in); } std::cout << std::max(0, ma - mi + 1) << std::endl; }