#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return f * x;
}
int n, a[10003], b[100003], lstx, lsty, ans = 1;
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    int x = read(), y = read();
    if (x == lstx && y == lsty) continue;
    bool op1 = lstx == lsty;
    if (lstx < lsty) {
      lstx = min(x, lsty);
      if (lstx == lsty) ans += min(x, y) - lsty + 1 - op1;
    } else {
      lsty = min(y, lstx);
      if (lstx == lsty) ans += min(x, y) - lsty + 1 - op1;
    }
    lstx = x;
    lsty = y;
  }
  cout << ans << '\n';
  return 0;
}
