#include <bits/stdc++.h>
using namespace std;
bool check[100007];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (i == 1)
      for (int j = (x); j <= (y - 1); ++j) check[j] = 1;
    else
      for (int j = (x); j <= (y - 1); ++j) check[j] = 0;
  }
  int ans = 0;
  for (int i = (0); i <= (100); ++i) ans += check[i];
  printf("%d\n", ans);
  return 0;
}
