#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int s, e;
  cin >> s >> e;
  if (n == 1) {
    cout << abs(s - e);
    return 0;
  }
  int ans = 0;
  int check[102] = {0};
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    for (int i = x; i < y; i++) check[i] = 1;
  }
  for (int i = s; i < e; i++) {
    if (!check[i]) ans++;
  }
  cout << ans;
}
