#include <bits/stdc++.h>
using namespace std;
long long n, a[10005], b[10005];
map<long long, int> mp;
long long ans, l, r;
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) scanf("%lld%lld", &a[i], &b[i]);
  for (int i = 1; i <= n; i++) {
    if (a[i] == a[i - 1] && b[i] == b[i - 1]) continue;
    r = min(a[i], b[i]);
    l = max(a[i - 1], b[i - 1]);
    if (r >= l && mp[l] == 0) {
      mp[l] = 1;
      ans++;
    }
    if (r > l) {
      ans += r - l;
      mp[r] = 1;
    }
  }
  if (ans == 0) ans++;
  printf("%lld\n", ans);
  return 0;
}
