#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a, b, res = 1, pa = 0, pb = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a, &b);
    if (a == pa && b == pb) continue;
    if (pa < pb) {
      pa = min(a, pb);
      if (pa == pb) res++;
    } else if (pa > pb) {
      pb = min(b, pa);
      if (pa == pb) res++;
    }
    if (pa == pb) res += min(b - pb, a - pa);
    pa = a;
    pb = b;
  }
  printf("%d\n", res);
  return 0;
}
