#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> mp;
  int n;
  cin >> n;
  int x1, y1;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (i == 0) {
      x1 = x;
      y1 = y;
    }
    mp[x]++;
    mp[y]--;
  }
  map<int, int>::iterator it;
  int count = 0;
  int prev;
  int ans = 0;
  for (it = mp.begin(); it != mp.end(); it++) {
    if (it->first > x1 && it->first <= y1) {
      if (count == 1) {
        ans += (it->first - prev);
      }
    }
    if (it->first > y1) {
      break;
    }
    prev = it->first;
    count += it->second;
  }
  cout << ans << "\n";
  return 0;
}
