#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define inf 0x3f3f3f3f
#define N 330
using namespace std;
inline char gc(){
static char now[1<<16],*S,*T;
if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
return *S++;
}
inline int read(){
int x=0;char ch=gc();
while(ch<'0'||ch>'9') ch=gc();
while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
return x;
}
int num=1,level[N],h[N],n,m,T;
struct node{
int y,z,next;
}data[N*N];
inline void insert1(int x,int y,int z){
data[++num].y=y;data[num].z=z;data[num].next=h[x];h[x]=num;
data[++num].y=x;data[num].z=0;data[num].next=h[y];h[y]=num;
}
inline bool bfs(){
memset(level,0,sizeof(level));level[0]=1;queue<int>q;q.push(0);
while(!q.empty()){
int x=q.front();q.pop();
for (int i=h[x];i;i=data[i].next){
int y=data[i].y,z=data[i].z;
if (level[y]||!z) continue;level[y]=level[x]+1;q.push(y);if (y==T) return 1;
}
}return 0;
}
inline int dfs(int x,int s){
if (x==T) return s;int ss=s;
for (int i=h[x];i;i=data[i].next){
int y=data[i].y,z=data[i].z;
if (level[x]+1==level[y]&&z){
int xx=dfs(y,min(s,z));if (!xx) level[y]=0;s-=xx;
data[i].z-=xx;data[i^1].z+=xx;if (!s) return ss;
}
}return ss-s;
}
int main(){
freopen("bzoj1934.in","r",stdin);
n=read();m=read();T=n+1;
for (int i=1;i<=n;++i){int x=read();if (x) insert1(0,i,1);else insert1(i,T,1);}
for (int i=1;i<=m;++i){
int x=read(),y=read();insert1(x,y,1);insert1(y,x,1);
}int ans=0; while(bfs()) ans+=dfs(0,inf);
printf("%d",ans);
return 0;
}