#include <bits/stdc++.h>
using namespace std;
int n, l, r;
bool a[101];
int main() {
  cin >> n;
  cin >> l >> r;
  for (int i = l; i < r; i++) {
    a[i] = 1;
  }
  n--;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    for (int i = l; i < r; i++) {
      a[i] = 0;
    }
  }
  int sum = 0;
  for (int i = 0; i < 100; i++) {
    sum += a[i];
  }
  cout << sum;
  return 0;
}
