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