#include<bits/stdc++.h>
#define endl "\n"
#define fr(ii,ss,tt) for(int ii=ss;ii<=tt;ii++)
#define rf(ii,ss,tt) for(int ii=ss;ii>=tt;ii--)
#define pii pair<int,int>
#define pt printf
#define fi first
#define eb emplace_back
#define ll long long
#define se second
using namespace std;
inline void rd(){}
template<typename T, typename... args>inline void rd(T&x, args&...y) {char ch;bool f = 0;for (ch = getchar(); ch < '0' || '9' < ch; ch = getchar())if (ch == '-')f = 1;for (x = 0; '0' <= ch && ch <= '9'; ch = getchar())x = (x << 1) + (x << 3) + ch - '0';if (f)x = -x;rd(y...);}
template<typename IT>void shw(const char* name,IT s,IT t){cout<<name<<"={";for(IT now=s;now!=t;now++){cout<<*now<<",";}cout<<"}\n";}
template<typename T>void toMax(T&x,const T&y){if(x<y)x=y;}
template<typename T>void toMin(T&x,const T&y){if(x>y)x=y;}
const int N = 1e6 + 33,inf=2e9;
int n,m;
vector<int> eg[N];
int fa[N],c[N];
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void un(int x,int y){
int fx=find(x);
int fy=find(y);
if(fx!=fy){
fa[fx]=fy;
}
}
int ea[N],eb[N];
int topo(){
static int in[N],f[N];//f(i) means the lenthgh of the longest path in the Graph
fr(i,1,n)in[i]=0,f[i]=-inf;
f[find(1)]=1;
fr(i,1,n){
for(int&t:eg[i]){
in[t]++;
}
}
static int q[N],hd,tl;
hd=0,tl=-1;
q[++tl]=find(1);
while(hd<=tl){
int s=q[hd++];
for(int&t:eg[s]){
in[t]--;assert(c[t]>c[s]);
toMax(f[t],f[s]+1);
if(!in[t]){
q[++tl]=t;
}
}
}
return f[find(n)];
}
int main() {
rd(n,m);
iota(fa+1,fa+n+1,1);
fr(i,1,n){
rd(c[i]);
}
fr(i,1,m){
int a,b;
rd(a,b);
if(c[a]<c[1]||c[b]<c[1])continue;
if(c[a]==c[b]){
un(a,b);
}
ea[i]=a;
eb[i]=b;
}
fr(i,1,m){
int a=ea[i];
int b=eb[i];
if(find(a)==find(b))continue;
if(c[a]>c[b])swap(a,b);
eg[find(a)].eb(find(b));
}
pt("%d\n",max(0,topo()));
return 0;
}