#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const double EPS = 1e-9;
const int N = 2e3 + 9;
int n, l, r, a[1009];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  cin >> l >> r;
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    cin >> x >> y;
    for (int j = x; j < y; j++) a[j] = 1;
  }
  int ans = 0;
  for (int i = l; i <= r - 1; i++) ans += !a[i];
  cout << ans;
  return 0;
}
