#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long sum = 1, x = 0, y = 0;
  for (long long i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    if (a == x && b == y) continue;
    long long d = 1 + min(a, b) - max(x, y);
    if (d > 0) sum += d;
    if (x == y) sum--;
    x = a;
    y = b;
  }
  cout << sum << endl;
  return 0;
}
