#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <stack>
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define l(x) (x<<1)
#define r(x) (x<<1|1)
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
struct node{
int a,b;
};
bool cmp(node x,node y){
return x.b<y.b;
}
bool cmp2(node x, node y){
return x.a<y.a;
}
int c,l;
node cow[2555],spf[2555];
int main() {
cin>>c>>l;
for(int i = 0;i<c;i++)
cin>>cow[i].a>>cow[i].b;
sort(cow,cow+c,cmp);
for(int i = 0;i<l;i++)
cin>>spf[i].a>>spf[i].b;
sort(spf,spf+l,cmp2);
int res = 0;
for(int i = 0;i<c;i++){
for(int j = 0;j<l;j++){
if(cow[i].b>=spf[j].a&&cow[i].a<=spf[j].a&&spf[j].b>0){
spf[j].b--;
res++;
break;
}
}
}
cout<<res<<endl;
return 0;
}