type rec=record
jus,num,min,max:longint;
end;
var n,m,i,p,ans,jus,j:longint;
a,b:array[1..2500]of rec;
u:array[1..2500]of boolean;
procedure qsorta(l,r:longint);
var t:rec;
i,j,midmax,midmin:longint;
begin
i:=l; j:=r;
midmax:=a[(l+r)div 2].max;
midmin:=a[(l+r)div 2].min;
while i<j do
begin
while (a[i].max<midmax)or((a[i].max=midmax)and(a[i].min<midmin)) do inc(i);
while (a[j].max>midmax)or((a[j].max=midmax)and(a[j].min>midmin)) do dec(j);
if i<=j then begin
t:=a[i]; a[i]:=a[j]; a[j]:=t;
inc(i);dec(j);
end;
end;
if l<j then qsorta(l,j);
if r>i then qsorta(i,r);
end;
procedure qsortb(l,r:longint);
var i,j,mid:longint;
t:rec;
begin
i:=l; j:=r;
mid:=b[(l+r)div 2].jus;
while i<j do
begin
while b[i].jus<mid do inc(i);
while b[j].jus>mid do dec(j);
if i<=j then begin
t:=b[i]; b[i]:=b[j]; b[j]:=t;
inc(i);dec(j);
end;
end;
if l<j then qsortb(l,j);
if r>i then qsortb(i,r);
end;
begin
readln(n,m);
for i:=1 to n do readln(a[i].min,a[i].max);
for i:=1 to m do readln(b[i].jus,b[i].num);
qsorta(1,n);
qsortb(1,m);
for i:=1 to m do begin
jus:=b[i].jus;
for j:=1 to n do
if (jus<=a[j].max)and(jus>=a[j].min)and(b[i].num>0)
then begin dec(b[i].num);
a[j].min:=maxlongint;
inc(ans);
end;
end;
writeln(ans);
close(input);
close(output);
end.