#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MAXN = 1e6 + 5, inf = 1e9;
const ll INF = 1e18;
const ld PI = 3.1415926535897932384626433832795;
ll a[MAXN], b[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << setprecision(13) << fixed;
  int n;
  cin >> n;
  vector<pair<int, int>> V = {{0, 0}};
  for (int i = 1; i <= n; i++) {
    int a, b;
    cin >> a >> b;
    V.push_back({a, b});
  }
  V.erase(unique(V.begin(), V.end()), V.end());
  if (V.size() == 1) {
    cout << 1 << "\n";
    return 0;
  }
  vector<pair<int, int>> v;
  for (int i = 1; i < V.size(); i++) {
    ll x = max(V[i - 1].first, V[i - 1].second);
    ll y = min(V[i].first, V[i].second);
    if (x > y) {
      continue;
    }
    v.push_back({x, y});
  }
  int last = 0;
  ll res = 1;
  for (auto i : v) {
    res += (i.second - i.first + 1);
    if (i.first == last) {
      res--;
    }
    last = i.second;
  }
  cout << res << "\n";
}
