#include <bits/stdc++.h>
using namespace std;
int main() {
  set<pair<int, int>> data, sub;
  int n, l, r, lin, rin;
  cin >> n >> l >> r;
  sub.insert(pair<int, int>(l, r));
  n--;
  for (int i = 0; i < n; i++) {
    cin >> lin >> rin;
    data.insert(pair<int, int>(lin, rin));
  }
  auto it = data.begin();
  while (it != data.end()) {
    auto it2 = it;
    it2++;
    while (it2 != data.end()) {
      if ((it->first == it2->first && it->second == it2->second) ||
          (it->first <= it2->first && it->second >= it2->second)) {
        data.erase(it2);
        it2 = it;
      } else if (it->first == it2->first && it2->second > it->second) {
        data.erase(it);
        it = data.begin();
        it2 = it;
      } else if (it2->first > it->first && it2->first <= it->second &&
                 it2->second >= it->second) {
        data.insert(pair<int, int>(it->first, it2->second));
        data.erase(it);
        data.erase(it2);
        it = data.begin();
        it2 = it;
      }
      it2++;
    }
    it++;
  }
  it = data.begin();
  while (it != data.end()) {
    auto it2 = sub.begin();
    while (it2 != sub.end()) {
      if (it->first <= it2->first && it->second >= it2->second) {
        sub.erase(it2);
        it2 = sub.begin();
      } else if (it->first > it2->first && it->second < it2->second) {
        sub.insert(pair<int, int>(it2->first, it->first));
        sub.insert(pair<int, int>(it->second, it2->second));
        sub.erase(it2);
        it2 = sub.begin();
      } else if (it->first > it2->first && it->first < it2->second &&
                 it->second >= it2->second) {
        sub.insert(pair<int, int>(it2->first, it->first));
        sub.erase(it2);
        it2 = sub.begin();
      } else if (it->second > it2->first && it->second < it2->second &&
                 it->first <= it2->first) {
        sub.insert(pair<int, int>(it->second, it2->second));
        sub.erase(it2);
        it2 = sub.begin();
      } else
        it2++;
    }
    it++;
  }
  int ans = 0;
  it = sub.begin();
  while (it != sub.end()) {
    ans += (it->second - it->first);
    it++;
  }
  cout << ans;
  return 0;
}
