#include <bits/stdc++.h>
using namespace std;
long long int x[111], y[111], z[111], n;
string s, S;
vector<long long int> v;
int main() {
  {
    long long int a = 0, b = 0, c = 0, d, e, f, g, i, j, k = 0, l, m, p, q, r,
                  u, w, t, tc, in, mod, loc, diff, val, sz, lo, hi, mid,
                  mn = 2134567891, mx = 0, sum = 0, ans = 0;
    cin >> n;
    memset(z, -1, sizeof(z));
    for (i = 0; i < n; i++) {
      cin >> p >> q;
      x[i] = p, y[i] = q;
      if (i == 0) {
        a = p, b = q;
        for (j = p; j <= q; j++) z[j] = 0;
      } else {
        for (j = p; j <= q; j++) z[j] = i;
      }
    }
    for (i = a; i <= b - 1; i++) {
      k = 0;
      for (j = 1; j <= n - 1; j++) {
        if (i >= y[j] || i < x[j]) {
          k++;
        }
      }
      if (k == n - 1) c++;
    }
    cout << c << endl;
  }
  return 0;
}
