#include <bits/stdc++.h>
using namespace std;
const int N=250+5;
int n,b;
int a[N],s[N],d[N];
int f[N];
int main(){
freopen ("snowboots_silver_18feb.in","r",stdin);
freopen ("snowboots_silver_18feb.out","w",stdout);
scanf("%d%d",&n,&b);
for (int i=1;i<=n;i++)scanf("%d",&a[i]);
for (int i=1;i<=b;i++)scanf("%d%d",&s[i],&d[i]);
memset(f,0x3f,sizeof(f));
f[1]=1;
for (int i=1;i<=n;i++){
for (int j=f[i];j<=b;j++){
int ss=s[j],dd=d[j];
for (int k=i+1;k<=min(i+dd,n);k++){
if (a[k]>ss||a[i]>ss)continue;
f[k]=min(f[k],j);
}
}
}
//for (int i=1;i<=n;i++)cout<<f[i]<<" ";
printf("%d\n",f[n]-1);
return 0;
}