#include <bits/stdc++.h>
using namespace std;
struct node {
  long long x, y;
  bool operator!=(const node& b) const { return x != b.x || y != b.y; }
} a[10005], A, B;
node solveL(node a) {
  if (a.y > a.x)
    a.x = a.y;
  else
    a.y = a.x;
  return a;
}
node solveR(node a) {
  if (a.y > a.x)
    a.y = a.x;
  else
    a.x = a.y;
  return a;
}
long long n;
int main() {
  ios::sync_with_stdio(false);
  while (cin >> n) {
    for (long long i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;
    node now;
    now.x = now.y = -1;
    long long ans = 0;
    for (long long i = 1; i <= n; i++) {
      if (!(now != a[i])) continue;
      A = solveL(now);
      B = solveR(a[i]);
      if (A.x < B.x) {
        ans += B.x - A.x;
        if (now.x != now.y) ans++;
      } else if (A.x == B.x) {
        if (now.x != now.y) ans++;
      }
      now = a[i];
    }
    cout << ans << endl;
  }
  return 0;
}
