#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int arr[100] = {0};
  int l, r, count = 0;
  cin >> l >> r;
  n--;
  int a, b;
  while (n--) {
    cin >> a >> b;
    for (int i = a; i < b; i++) {
      arr[i] = 1;
    }
  }
  for (int i = l; i < r; i++) {
    if (!arr[i]) count++;
  }
  cout << count;
}
