#include <bits/stdc++.h>
using namespace std;
int n;
int x, y, usd[1001];
int main() {
  cin >> n;
  int pos1 = 0, pos2 = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> x >> y;
    if (i == 1) {
      pos1 = x;
      pos2 = y;
    } else {
      for (int j = x; j < y; ++j) {
        usd[j] = 1;
      }
    }
  }
  int cnt = 0;
  cout << endl;
  for (int i = pos1; i < pos2; ++i) {
    if (!usd[i]) ++cnt;
  }
  cout << cnt;
}
