#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; map L; map> R; for(int i=0; i> l >> r; L[l-N]++; R[r-1]++; } int maxl = -1e9,minr = 2e9; for(auto [k,v] : L){ if(v >= 2) L[k+1] += v-1; if(v) maxl = max(maxl,k); } for(auto [k,v] : R){ if(v >= 2) R[k-1] += v-1; if(v) minr = min(minr,k); } cout << max(0,minr-maxl+1) << endl; }