#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define rng(a) a.begin(),a.end() using namespace std; typedef long long int ll; typedef pair P; typedef vector vi; typedef vector vvi; typedef vector vl; typedef vector

vp; #define dame { puts("-1"); return 0;} #define yn {puts("Yes");}else{puts("No");} #define MAX_N 200005 int main() { int n; cin >> n; int a[n]; int b[n]; int diff = 0; srep(i,1,n){ cin >> a[i] >> b[i]; diff += b[i] - a[i]; } int c[n]; int ans = 0; rep(i,1000005){ a[0] = i; b[0] = i + diff; if(b[0] < 0) continue; int ma = 0; int sum = 0; rep(j,n){ ma = max(ma, a[j]+b[j]); sum += a[j]; } if(ma <= sum)ans++; } cout << ans << endl; return 0; }