Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. 

The dorm has exactly one straight dryer — a 100 centimeter long rope to hang clothes on. The dryer has got a coordinate system installed: the leftmost end of the dryer has coordinate 0, and the opposite end has coordinate 100. Overall, the university has n students. Dean's office allows i-th student to use the segment (li, ri) of the dryer. However, the dean's office actions are contradictory and now one part of the dryer can belong to multiple students!

Alexey don't like when someone touch his clothes. That's why he want make it impossible to someone clothes touch his ones. So Alexey wonders: what is the total length of the parts of the dryer that he may use in a such way that clothes of the others (n - 1) students aren't drying there. Help him! Note that Alexey, as the most respected student, has number 1.

Input

The first line contains a positive integer n (1 ≤ n ≤ 100). The (i + 1)-th line contains integers li and ri (0 ≤ li < ri ≤ 100) — the endpoints of the corresponding segment for the i-th student.

Output

On a single line print a single number k, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments.

Examples

Input

3
0 5
2 8
1 6


Output

1


Input

3
0 10
1 5
7 15


Output

3

Note

Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments.

In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and (2, 8). The length of segment (0, 1) is 1.

In the second test sample Alexey may dry his clothes on segments (0, 1) and (5, 7). Overall length of these segments is 3.
#include <bits/stdc++.h>
using namespace std;
long long ESP = 1e18;
bool isPrime[5000005];
void sieve(long long int N) {
  for (long long i = 0; i <= N; ++i) {
    isPrime[i] = true;
  }
  isPrime[0] = false;
  isPrime[1] = false;
  for (int i = 2; i * i <= N; ++i) {
    if (isPrime[i] == true) {
      for (int j = i * i; j <= N; j += i) isPrime[j] = false;
    }
  }
}
bool anagram(char *s1, char *s2) {
  long long count[256];
  memset(count, 0, sizeof(count));
  long long i;
  for (i = 0; s1[i] && s2[i]; i++) {
    count[s1[i]]++;
    count[s2[i]]--;
  }
  if (s1[i] || s2[i]) {
    return false;
  }
  for (int(i) = (int)(0); i < (int)(256); ++i) {
    if (count[i]) {
      return false;
    }
  }
  return true;
}
int find_largest_digit(int n) {
  int mx = 0;
  while (n > 0) {
    mx = max(mx, n % 10);
    n /= 10;
  }
  return mx;
}
long long no_of_digits(long long n) {
  long long ans = 0;
  while (n > 0) {
    ans++;
    n /= 10;
  }
  return ans;
}
long long moduloMultiplication(long long a, long long b, long long zz) {
  long long res = 0;
  a %= zz;
  while (b) {
    if (b & 1) res = (res + a) % zz;
    a = (2 * a) % zz;
    b >>= 1;
  }
  return res;
}
long long convert(string s) {
  bool o = true;
  long long ans = 0;
  for (long long i = 0; i < s.length(); i++) {
    ans = ans * 10 + (s[i] - 48);
  }
  return ans;
}
inline long long powmod(long long a, long long b, long long modulo) {
  if (b == 0 || a == 1) return 1;
  long long half = powmod(a, (b / 2), modulo) % modulo;
  long long full = (half * half) % modulo;
  if (b % 2) return (full * a) % modulo;
  return full % modulo;
}
long long poww(long long a, long long b) {
  if (b == 0 || a == 1) return 1;
  long long half = poww(a, (b / 2));
  if (half < 0 || half > ESP) return -1;
  long long full = (half * half);
  if (half != 0 && full / half != half) {
    return -1;
  }
  if (b % 2) {
    if (full * a < 0 || full * a > ESP) return -1;
  }
  if (full < 0 || full > ESP) return -1;
  if (b % 2) {
    long long x = a * full;
    if (a != 0 && x / a != full) {
      return -1;
    }
    return (x);
  }
  return full;
}
long long invmod(long long a, long long modulo) {
  long long check = powmod(a, modulo - 2, modulo) % modulo;
  return check;
}
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  }
  return b;
}
long long min(long long a, long long b) {
  if (a < b) {
    return a;
  }
  return b;
}
long long min(long long a, int b) {
  if (a < b) return a;
  return b;
}
long long min(int a, long long b) {
  if (a < b) return a;
  return b;
}
long long max(long long a, int b) {
  if (a > b) return a;
  return b;
}
long long max(int a, long long b) {
  if (a > b) return a;
  return b;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
void yes() {
  cout << "YES"
       << "\n";
}
void no() {
  cout << "NO"
       << "\n";
}
vector<int> factorize(int n) {
  vector<int> res;
  for (int i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res.push_back(i);
      n /= i;
    }
  }
  if (n != 1) {
    res.push_back(n);
  }
  return res;
}
void printDivisors(int n) {
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        printf("%d ", i);
      else
        printf("%d %d ", i, n / i);
    }
  }
}
int phi(int n) {
  int result = n;
  for (int p = 2; p * p <= n; ++p) {
    if (n % p == 0) {
      while (n % p == 0) n /= p;
      result -= result / p;
    }
  }
  if (n > 1) result -= result / n;
  return result;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int al, ar;
  cin >> al >> ar;
  list<int> alex;
  int fans = 0;
  for (int(i) = (int)(0); i < (int)(ar - al + 1); ++i) {
    alex.push_back(al + i);
  }
  set<int> zz, yy;
  int l[n - 1], r[n - 1];
  for (int(i) = (int)(1); i < (int)(n); ++i) {
    cin >> l[i - 1] >> r[i - 1];
  }
  for (int(i) = (int)(1); i < (int)(n); ++i) {
    if (r[i - 1] <= ar && l[i - 1] >= al && r[i - 1] - l[i - 1] == 1) {
      zz.insert(l[i - 1]);
      continue;
    } else {
      for (int(z) = (int)(1); z < (int)(n); ++z) {
        if (r[z - 1] - l[z - 1] != 1) {
          for (int k : zz) {
            if (l[z - 1] <= k && k + 1 <= r[z - 1]) {
              yy.insert(k);
            }
          }
        }
      }
    }
    for (int(j) = (int)(l[i - 1] + 1); j < (int)(r[i - 1]); ++j) {
      alex.remove(j);
    }
  }
  int ans[100];
  int i = 0;
  for (decltype(alex.begin()) it = alex.begin(); it != alex.end(); it++) {
    ans[i] = *it;
    i++;
  }
  int size = i;
  sort(ans, ans + size);
  for (int(i) = (int)(0); i < (int)(size - 1); ++i) {
    if (ans[i] + 1 == ans[i + 1]) {
      fans++;
    }
  }
  fans -= zz.size() - yy.size();
  if (fans < 0) fans = 0;
  cout << fans << '\n';
  return 0;
}
