#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> vp;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    vp.push_back(make_pair(x, y));
  }
  int b[1000] = {0};
  for (int i = vp[0].first; i < vp[0].second; i++) {
    b[i] = 1;
  }
  int ans;
  for (int i = 1; i < n; i++) {
    for (int j = vp[i].first; j < vp[i].second; j++) {
      b[j] = 0;
    }
  }
  ans = 0;
  for (int i = 0; i < 1000; i++) {
    ans = ans + b[i];
  }
  cout << ans;
}
