#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int main() {
  ios::sync_with_stdio(false);
  int n, a[101] = {0}, x, y, res = 0, xx, yy;
  cin >> n >> xx >> yy;
  for (int i = (1); i < (n); i++) {
    cin >> x >> y;
    for (int j = (x); j < (y); j++) a[j]++;
  }
  for (int i = (xx); i < (yy); i++)
    if (!a[i]) res++;
  cout << res << endl;
  return 0;
}
