include [HTML_REMOVED]
using namespace std;
int n,m,ans=0;
struct node{
int x,y;
}k[6666];
struct nodede{
int s,t;
}f[6666];
bool cmp(node a,node b){
if(a.x>b.x)return 1;
else if(a.x==b.x){
if(a.y[HTML_REMOVED]b.s)return 1;
else return 0;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i)
cin>>k[i].x>>k[i].y;
sort(k+1,k+1+n,cmp);
for(int i=1;i<=m;i)
cin>>f[i].s>>f[i].t;
sort(f+1,f+1+m,cmpmp);
for(int i=1;i<=n;i){
for(int j=1;j<=m;j){
if(f[j].t>0&&k[i].x<=f[j].s&&f[j].s<=k[i].y){
ans++;
f[j].t–;
break;
}
}
}
cout<<ans;
return 0;
}