#include <bits/stdc++.h>
using namespace std;
void FastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int n, x, y, l, r, answer;
struct Interval {
  int start, end;
  Interval(const int &a, const int &b) : start(a), end(b) {}
};
vector<Interval> intervals;
void Add(const Interval &a) {
  for (int i = 0; i < intervals.size(); i++) {
    int st = intervals[i].start, en = intervals[i].end;
    if (a.start == st && a.end == en) goto equal;
    if (st >= en) {
      intervals.erase(intervals.begin() + i);
      i--;
      continue;
    }
    if (a.end <= st || a.start >= en) continue;
    if (a.start <= st && a.end <= en) intervals[i].start = a.end;
    if (a.start >= st && a.end >= en)
      intervals[i].end = a.start;
    else {
      if (st != a.start) intervals.push_back(Interval(st, a.start));
      if (en != a.end) intervals.push_back(Interval(a.end, en));
    equal:
      intervals.erase(intervals.begin() + i);
      i--;
    }
  }
}
int main() {
  FastIO();
  answer = 0;
  cin >> n >> x >> y;
  intervals.push_back(Interval(x, y));
  for (int i = 1; i < n; i++) {
    cin >> l >> r;
    Add(Interval(l, r));
  }
  for (int i = 0; i < intervals.size(); i++)
    answer += intervals[i].end - intervals[i].start;
  cout << answer << "\n";
  return 0;
}
