#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;
//英语 看博友分析 抄博友程序 枚举没实现 优先队列实现 贪心 背
struct cow{
int l;
int r;
};
bool cmp1(cow a,cow b)
{
return a.l<b.l;
}
struct lot{
int zhi;
int num;
};
bool cmp2(lot a,lot b)
{
return a.zhi<b.zhi;
}
int main()
{
int n,m;
cin>>n>>m;
vector<cow> da;
for(int i=0;i<n;i++)
{
cow t;
cin>>t.l>>t.r;
da.push_back(t);
}
sort(da.begin(),da.end(),cmp1);
vector<lot> ve;
for(int i=0;i<m;i++)
{
lot t;
cin>>t.zhi>>t.num;
ve.push_back(t);
}
sort(ve.begin(),ve.end(),cmp2);
priority_queue<int,vector<int>,greater<int> > que;//必须是优先队列 不漏牛
int j=0;//牛
int jg=0;
for(int i=0;i<ve.size();i++)//枚举防嗮霜
{
while(j<da.size() && ve[i].zhi>=da[j].l)//有条件
{
que.push(da[j].r);
j++;
}
while(que.empty()!=1 && ve[i].num>0)
{
int t=que.top();
que.pop();
if(t>=ve[i].zhi)
{
jg++;
ve[i].num--;
}
}
}
cout<<jg<<endl;
return 0;
}