#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(25);
  ;
  int n;
  int sum = 0;
  cin >> n;
  int l1, r1, l, r = 0;
  cin >> l1 >> r1;
  n = n - 1;
  vector<int> v(r1, 0);
  while (n--) {
    cin >> l >> r;
    for (int i = l; i < min(r, r1); i++) {
      v[i] = 1;
    }
  }
  for (int j = l1; j < r1; j++) {
    if (v[j] == 0) sum = sum + 1;
  }
  cout << sum << endl;
  return 0;
}
