#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int mx = 1e5 + 10;
long long int binpow(long long int base, long long int exp) {
  long long int res = 1;
  while (1) {
    if (exp & 1) res *= base;
    exp >>= 1;
    if (!exp) break;
    base *= base;
  }
  return res;
}
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  n--;
  int c, k;
  cin >> c >> k;
  int arr[110] = {0};
  int d, f;
  bool same = 0;
  for (int j = 0; j < n; ++j) {
    cin >> d >> f;
    if (d == c && f == k) same = 1;
    for (int i = d; i < f; ++i) {
      arr[i] = 1;
    }
  }
  if (same) {
    cout << 0 << "\n";
    return 0;
  }
  int ans = 0, cnt = 0, last = c;
  for (int i = c; i < k; ++i) {
    if (!arr[i]) ans++;
  }
  cout << ans << "\n";
  return 0;
}
