#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
  int n;
  int l, r;
  cin >> n >> l >> r;
  for (register int i = 2; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    for (register int j = x + 1; j <= y; j++) a[j]++;
  }
  int ans = 0;
  for (register int i = l + 1; i <= r; i++) {
    if (a[i] == 0) ans++;
  }
  cout << ans;
  return 0;
}
