#include <bits/stdc++.h>
using namespace std;
bool used[102];
int main() {
  int n;
  int x, y, a, b;
  cin >> n;
  cin >> x >> y;
  for (int i = 0; i <= 100; i++) used[i] = false;
  for (int i = 1; i < n; i++) {
    cin >> a >> b;
    for (int j = a; j < b; j++) used[j] = true;
  }
  int cnt = 0;
  for (int i = x; i < y; i++) {
    if (!used[i]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}
