include [HTML_REMOVED]
using namespace std;
int main()
{
int n;
cin>>n;
int h[1000005]={0};
for(int i=1;i<=n;i){
int x,y;
cin>>x>>y;
for(int j=x+1;j<=y;j){
h[j]=1;
}
}
int cnt=0;
for(int i=1;i<=n;i){
int x,y;
cin>>x>>y;
for(int j=x+1;j<=y;j){
if(h[j]==1)
cnt++;
}
}
printf(“%d\n”,cnt);
return 0;
}