#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const int maxn = 111;
int n;
int a[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  int x, y;
  cin >> x >> y;
  for (int i = x + 1; i <= y; i++) {
    a[i] = 1;
  }
  for (int i = 0; i < n - 1; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l + 1; j <= r; j++) {
      a[j] = 0;
    }
  }
  int ans = 0;
  for (int i = 0; i <= 100; i++) {
    ans += a[i];
  }
  out(ans);
  return 0;
}
