#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int f(int l1, int r1, int l2, int r2) {
  int x;
  x = min(r1, r2) - max(l1, l2) + 1;
  if (x < 0) return 0;
  return x;
}
int main() {
  bool test_variable = false;
  if (test_variable) {
    int t;
    scanf("%d\n", &t);
    while (t--) {
    }
  } else {
    int l, r;
    int n;
    cin >> n;
    int arr[n + 1], b[n + 1];
    int s = 0;
    for (int i = 1; i <= n; i++) cin >> arr[i] >> b[i];
    arr[0] = 0;
    b[0] = 0;
    int temp;
    for (int i = 1; i <= n; i++) {
      temp = f(arr[i - 1], arr[i], b[i - 1], b[i]);
      s += temp;
      if (arr[i] == b[i]) s--;
    }
    if (arr[n] == b[n]) s++;
    cout << s;
  }
  return 0;
}
