#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, x, y, j, count = 0;
  int arr[100] = {0};
  cin >> n;
  cin >> x >> y;
  for (j = x; j < y; j++) arr[j] = 2;
  for (i = 1; i < n; i++) {
    cin >> x >> y;
    for (j = x; j < y; j++) {
      arr[j] = 0;
    }
  }
  for (i = 0; i < 100; i++) {
    if (arr[i] == 2) count++;
  }
  cout << count;
  return 0;
}
