#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  return out << "(" << a.first << "," << a.second << ")";
}
template <class A>
ostream &operator<<(ostream &out, const vector<A> &a) {
  for (const A &it : a) out << it << " ";
  return out;
}
template <class A, class B>
istream &operator>>(istream &in, pair<A, B> &a) {
  return in >> a.first >> a.second;
}
template <class A>
istream &operator>>(istream &in, vector<A> &a) {
  for (A &i : a) in >> i;
  return in;
}
ifstream cinn("in.txt");
ofstream coutt("out.txt");
long long poww(const long long &a, long long b,
               const long long &m = 1000000007) {
  if (b == 0) return 1;
  long long first = poww(a, b / 2, m);
  first = first * first % m;
  if (b & 1) first = first * a % m;
  return first;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long _sum(long long n) { return (n * (n + 1)) / 2; }
long long distSq(pair<long long, long long> p, pair<long long, long long> q) {
  return (p.first - q.first) * (p.first - q.first) +
         (p.second - q.second) * (p.second - q.second);
}
vector<long long> fact(101);
long long nCr(long long n, long long r) {
  if (!r) return 1;
  return (n * nCr(n - 1, r - 1)) / r;
}
const long long N = 1e6 + 5;
vector<pair<long long, long long> > adj[105];
long long vis[105];
bool dfs(long long n, long long col, long long des) {
  vis[n] = 1;
  if (n == des) return true;
  for (pair<long long, long long> a : adj[n]) {
    if (a.second == col && !vis[a.first]) {
      bool ok = dfs(a.first, col, des);
      if (ok) return true;
    }
  }
  return false;
}
bool isPalindrome(string str) {
  long long low = 0;
  long long high = str.length() - 1;
  while (low < high) {
    if (str[low] != str[high]) {
      return false;
    }
    low++;
    high--;
  }
  return true;
}
long long ok(vector<pair<long long, long long> > &v, long long pos) {
  long long s = 0, i;
  for (i = pos; i < (long long)(v).size(); i++) {
    s += v[i].second;
  }
  return s;
}
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  return a.second >= b.first;
}
void build_tree(long long l, long long r, vector<long long> &v,
                vector<long long> &d, long long curd) {
  if (l > r) return;
  if (l == r) {
    d[l] = curd;
  }
  long long mx = l, i;
  for (i = l + 1; i < r + 1; i++) {
    if (v[mx] < v[i]) {
      mx = i;
    }
  }
  d[mx] = curd;
  build_tree(l, mx - 1, v, d, curd + 1);
  build_tree(mx + 1, r, v, d, curd + 1);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t, n, c, b, m, k, f, f2, t2, t3, i, j, ans, mnt, mxt, j1, j2, a;
  cin >> n;
  long long st = 0, en = 0;
  ans = 0;
  c = 1;
  vector<pair<long long, long long> > v;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    if (v.empty() || v.back() != make_pair(a, b)) {
      v.push_back({a, b});
    }
  }
  map<long long, long long> mm;
  if (v[0] != make_pair((long long)0, (long long)0) ||
      ((long long)(v).size() == 1 && v[0] == make_pair(0ll, 0ll))) {
    ans += min(v[0].second, v[0].first) + 1;
    mm[min(v[0].second, v[0].first)]++;
  }
  for (i = 1; i < (long long)(v).size(); i++) {
    long long mx = min(v[i].first, v[i].second),
              mn = max(v[i - 1].first, v[i - 1].second);
    if (mm.count(mn) == 1) {
      ans += max(0ll, mx - mn);
      mm[mx]++;
    } else {
      ans += max(0ll, mx - mn + 1);
      mm[mx]++;
    }
  }
  cout << ans << '\n';
}
