#include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 1000 + 10;
int n, m;
int len[maxn];
int f, mc;
int cnt = 0;
struct node
{
int l;
int r;
int c;
bool b[maxn];
}p[maxn];
int main()
{
freopen("bg.in","r",stdin);
freopen("bg.out","w",stdout);
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> len[i];
for (int i = 1; i <= m; i++)
{
cin >> p[i].l >> p[i].r;
p[i].c = p[i].r - p[i].l;
}
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
{
p[i].b[j] = false;
if (len[j] >= p[i].l && len[j] <=p[i].r)
p[i].b[j] = true;
}
bool x;
for (int i = 1; i <= n; i++)
{
mc = 200000;
x = false;
for (int j = 1; j <= m; j++)
{
if (p[j].b[i] == true)
{
if (p[j].c < mc)
{
mc = p[j].c;
f = j;
x = true;
}
}
}
if (x == true)
{
cnt++;
for (int k = 1; k <= n; k++)
{
p[f].b[k] = false;
}
}
}
cout << cnt;
return 0;
}