/**************************************************************
Problem: 2768
User: winmt
Language: C++
Result: Accepted
Time:32 ms
Memory:3064 kb
****************************************************************/
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<utility>
#include<map>
#include<set>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<functional>
#include<sstream>
#include<cstring>
#include<bitset>
#include<stack>
using namespace std;
int n,m,s,t,cnt=1,x,y,z;
struct sdt
{
int cap,flow,u,v;
}e[90305];
int nxt[90305],fir[305],d[305],par[305],num[305],cur[305];
bool vis[305];
int read()
{
int x=0;char c=getchar();
while(c<48||c>57)c=getchar();
while(c>47&&c<58)x*=10,x+=c-48,c=getchar();
return x;
}
void add(int u,int v,int cp,int fl)
{
e[++cnt].u=u;e[cnt].v=v;e[cnt].cap=cp;e[cnt].flow=fl;
nxt[cnt]=fir[u];fir[u]=cnt;
}
void bfs()
{
//memset(vis,0,sizeof(vis));
//memset(d,0,sizeof(d));
queue<int>q;
d[t]=0;
vis[t]=1;
q.push(t);
while(!q.empty())
{
int k=q.front();
q.pop();
for(int i=fir[k];i;i=nxt[i])
{
if(!vis[e[i].v] && e[i].cap==0)
{
vis[e[i].v]=1;
d[e[i].v]=d[k]+1;
q.push(e[i].v);
}
}
}
}
int agument()
{
int p=t;
int ans=2147483647;
while(p!=s)
{
ans=min(ans,e[par[p]].cap-e[par[p]].flow);
p=e[par[p]].u;
}
p=t;
while(p!=s)
{
e[par[p]].flow+=ans;
e[par[p]^1].flow-=ans;
p=e[par[p]].u;
}
return ans;
}
int isap()
{
//memset(num,0,sizeof(num));
int flow=0;
for(int i=1;i<=t;i++)
{
num[d[i]]++;
cur[i]=fir[i];
}
int p=s;
while(d[s]<t)
{
if(p==t)
{
flow+=agument();
p=s;
}
bool ok=0;
for(int i=cur[p];i;i=nxt[i])
{
if(e[i].cap>e[i].flow && d[p]==d[e[i].v]+1)
{
ok=1;
par[e[i].v]=i;
cur[p]=i;
p=e[i].v;
break;
}
}
if(!ok)
{
int mn=t-1;
for(int i=fir[p];i;i=nxt[i])
{
if(e[i].cap>e[i].flow)mn=min(mn,d[e[i].v]);
}
if(--num[d[p]]==0)break;
num[d[p]=mn+1]++;
cur[p]=fir[p];
if(p!=s)p=e[par[p]].u;
}
}
return flow;
}
int main()
{
n=read();m=read();
//memset(nxt,0,sizeof(nxt));
//memset(fir,0,sizeof(fir));
s=1;
t=n+2;
for(int i=1;i<=n;i++)
{
z=read();
if(z)
{
add(s,i+1,1,0);
add(i+1,s,0,0);
}
else
{
add(i+1,t,1,0);
add(t,i+1,1,0);
}
}
for(int i=1;i<=m;i++)
{
x=read();y=read();
add(1+x,1+y,1,0);
add(y+1,x+1,1,0);
}
bfs();
printf("%d\n",isap());
return 0;
}