1 # include<cstdio>
2 # include<cstring>
3 # include<cstdlib>
4 # include<iostream>
5 # include<algorithm>
6 using namespace std;
7 const int maxn=2505;
8 int n,m,ans;
9 struct arr
10 {
11 int x,y,i;
12 }a[maxn];
13 struct brr
14 {
15 int spf,sum;
16 }b[maxn];
17 struct crr
18 {
19 int v,i;
20 }c[maxn];
21 bool t[maxn];
22 bool cmp1(arr i,arr j){return i.x<j.x;}
23 bool cmp2(brr i,brr j){return i.spf<j.spf;}
24 bool cmp3(crr i,crr j){return i.v<j.v;}
25 void Init()
26 {
27 scanf("%d%d",&n,&m);
28 int i;
29 for (i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y);
30 for (i=1;i<=m;i++) scanf("%d%d",&b[i].spf,&b[i].sum);
31 sort(a+1,a+n+1,cmp1);
32 sort(b+1,b+m+1,cmp2);
33 }
34 void Work()
35 {
36 int tot;
37 for (int i=1;i<=m;i++)
38 {
39 tot=0;
40 for (int j=1;a[j].x<=b[i].spf&&j<=n;j++)
41 if (!t[j]&&b[i].spf<=a[j].y) {c[++tot].v=a[j].y;c[tot].i=j;}
42 if (tot>b[i].sum) {sort(c+1,c+tot+1,cmp3);tot=b[i].sum;}
43 for (int j=1;j<=tot;j++) t[c[j].i]=1;
44 ans+=tot;
45 }
46 printf("%d\n",ans);
47 }
48 int main()
49 {
50 Init();
51 Work();
52 return 0;
53 }