#include<bits/stdc++.h>usingnamespace std;constint N =2010;
vector<pair<int,int>>H(N);int n;int ans =0;intmain(){
cin >> n;for(int i =0; i < n;++i){
cin >> H[i].first >> H[i].second;}int x, y;for(int i =0; i < n;++i){
cin >> x >> y;for(int j =0; j < n;++j){if((x >= H[j].first && x < H[j].second)||(y > H[j].first && y <= H[j].second)||(x < H[j].first && y > H[j].second)){int left =max(x, H[j].first);int right =min(y, H[j].second);
ans += right - left;}}}
cout<< ans << endl;return0;}