#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(cin >> n){
int a,b,m=0,ans=0;
while(n--){
cin >> a >> b;
if(min(a,b) >= m)ans += min(a,b) - m + 1;
if(a == b) m = a+1;
else m = max(a,b);
}
cout << ans << endl;
}
return 0;
}