#include <bits/stdc++.h>
using namespace std;
int n, a[111], b, e, x, y, res;
int main() {
  scanf("%d", &n);
  scanf("%d%d", &b, &e);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &x, &y);
    for (int j = x; j < y; ++j) a[j] = 1;
  }
  for (int i = b; i < e; ++i)
    if (!a[i]) ++res;
  printf("%d", res);
  return 0;
}
