#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
static mt19937 _g(time(nullptr));
inline long long int randint(long long int a, long long int b) {
  long long int w = (_g() << 31LL) ^ _g();
  return a + w % (b - a + 1);
}
inline void fast_io() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
};
template <typename T>
inline T sign(T x) {
  return T(x > 0) - T(x < 0);
}
void solve() {
  int n;
  cin >> n;
  vector<pair<long long int, long long int> > data(n);
  long long int ans = 0;
  for (auto& el : data) {
    cin >> el.first >> el.second;
  }
  data.insert(data.begin(), make_pair(0, 0));
  for (int i = 0; i < n; ++i) {
    long long int L1 = data[i].first, R1 = data[i + 1].first;
    long long int L2 = data[i].second, R2 = data[i + 1].second;
    long long int dlt = max(0LL, min(R1, R2) - max(L1, L2) + 1 - (R1 == R2));
    ;
    ans += dlt;
  }
  if (data.back().first == data.back().second) ++ans;
  cout << ans << endl;
}
int main(int argc, char** argv) {
  fast_io();
  solve();
  return 0;
}
