#include <bits/stdc++.h>
using namespace std;
const int ms = int(1.5e4) + 100;
int arr[101];
int main() {
  int cnt = 0;
  int n, a, b;
  cin >> n;
  cin >> a >> b;
  for (int i = a; i < b; i++) arr[i] = 1;
  for (int j = 0; j < n - 1; j++) {
    cin >> a >> b;
    for (int i = a; i < b; i++) arr[i] = 0;
  }
  for (int i = 0; i < 101; i++) cnt += arr[i];
  cout << cnt << endl;
}
