#include <bits/stdc++.h>
using namespace std;
int n, x, y, a, b, arr[102], cnt;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> a >> b;
  n--;
  while (n--) {
    cin >> x >> y;
    for (int i = x; i < y; i++) arr[i] = 1;
  }
  for (int i = a; i < b; i++) cnt += !arr[i];
  cout << cnt << endl;
  return 0;
}
