#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int s[101];
int main(void) {
  int n, l, r, L, R;
  scanf("%d", &n);
  scanf("%d%d", &L, &R);
  for (int i = L; i < R; i++) s[i] = 1;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &l, &r);
    for (int j = l; j < r; j++) s[j] = 0;
  }
  int ans = 0;
  for (int i = 0; i <= 100; i++) {
    ans += s[i];
  }
  printf("%d\n", ans);
}
