#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int arr[100];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, x, y, a, b;
  cin >> n >> x >> y;
  while (--n) {
    cin >> a >> b;
    fill(arr + a, arr + b, 1);
  }
  int t = 0;
  for (int i = x; i < y; ++i)
    if (!arr[i]) ++t;
  cout << t;
  return 0;
}
