#include<cstdio>
#include<algorithm>
using namespace std;
class v
{
public:
int l,r;
}x[100100]={0};
bool O(v x,v y)
{
if (x.l==y.l) return x.r<y.r;
else return x.l<y.l;
}
int s[100100]={0};
int main()
{
freopen("bg.in","r",stdin);
freopen("bg.out","w",stdout);
int n,m;
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
scanf("%d",&s[i]);
for (int i=1;i<=m;i++)
scanf("%d%d",&x[i].l,&x[i].r);
sort(s+1,s+n+1);
sort(x+1,x+m+1,O);
int num=0,tot=1,l;
if (n<m) l=n;
else l=m;
for (int i=1;i<=l;i++)
{
while(s[tot]<x[i].l) tot++;
if (s[tot]<=x[i].r)
{
num++;
tot++;
}
}
printf("%d",num);
}