#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, f, g, h, j, k, l, check[11111], cnt;
int main() {
  cin >> a;
  cin >> b >> c;
  for (int i = 1; i < a; ++i) {
    cin >> d >> e;
    for (int j = d; j < e; ++j) {
      check[j] = 1;
    }
  }
  for (int i = b; i < c; ++i) {
    if (!check[i]) {
      cnt++;
    }
  }
  cout << cnt;
}
