#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  long long a[n], b[n];
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  long long count = 0;
  count = min(a[0], b[0]) + 1;
  for (int i = 1; i < n; i++) {
    if (a[i] == a[i - 1] && b[i] == b[i - 1])
      continue;
    else if ((min(a[i - 1], b[i - 1]) == a[i - 1] && a[i] < b[i - 1]) ||
             (min(a[i - 1], b[i - 1]) == b[i - 1] && b[i] < a[i - 1]))
      continue;
    else {
      long long x[4];
      x[0] = a[i - 1];
      x[1] = a[i];
      x[2] = b[i];
      x[3] = b[i - 1];
      sort(x, x + 4);
      count += (x[2] - x[1]) + 1;
      if (a[i - 1] == b[i - 1]) count--;
    }
  }
  cout << count;
  return 0;
}
