#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
inline int read() {
  char ch = getchar();
  int u = 0, f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    u = u * 10 + ch - 48;
    ch = getchar();
  }
  return u * f;
}
int a[maxn], n, ans, Lx, Ly, L;
int main() {
  n = read();
  Lx = -1;
  Ly = -1;
  L = 0;
  for (register int i = 1; i <= n; ++i) {
    int x = read(), y = read();
    int T = min(x, y), P = max(Lx, Ly);
    P = max(L, P);
    ans += max(T - P + 1, 0);
    L = T + 1;
    Lx = x;
    Ly = y;
  }
  cout << ans << endl;
  return 0;
}
