#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=10010;
const int M=20010;
const int mod=1000000007;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const int INF=1000000010;
const ll MAX=1ll<<55;
const double eps=1e-5;
const double inf=~0u>>1;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
struct Edge {
int u,v,id,iscut;
Edge() {}
Edge(int u,int v,int id) {
this->u=u;this->v=v;this->id=id;this->iscut=0;
}
}cut[M],edge[2*M];
int n,tot,val[N],first[N],nex[2*M];
void init() {
tot=0;memset(first,-1,sizeof(first));
}
void add_edge(int u,int v,int id) {
edge[tot]=Edge(u,v,id);nex[tot]=first[u];first[u]=tot++;
}
int ans,sum,cutn,dfs_clock,pre[N],dfn[N],siz[N];
void dfs_cut(int u,int fa) {
pre[u]=dfn[u]=++dfs_clock;siz[u]=val[u];
for (int i=first[u];~i;i=nex[i])
if (edge[i].id!=fa) {
int v=edge[i].v,id=edge[i].id;
if (!pre[v]) {
dfs_cut(v,id);siz[u]+=siz[v];
dfn[u]=min(dfn[u],dfn[v]);
if (dfn[v]>pre[u]) {
cut[cutn++]=edge[i];
ans=min(ans,abs(2*siz[v]-sum));
edge[i].iscut=edge[i^1].iscut=1;
}
} else dfn[u]=min(dfn[u],pre[v]);
}
}
void find_cut() {
dfs_clock=cutn=0;
memset(pre,0,sizeof(pre));
for (int i=0;i<n;i++)
if (!pre[i]) dfs_cut(i,-1);
}
int main()
{
int a,b,i,m;
while (scanf("%d%d", &n, &m)!=EOF) {
init();sum=0;
for (i=0;i<n;i++) scanf("%d", &val[i]),sum+=val[i];
for (i=1;i<=m;i++) {
scanf("%d%d", &a, &b);
add_edge(a,b,i);add_edge(b,a,i);
}
ans=INF;find_cut();
if (!cutn) printf("impossible\n");
else printf("%d\n", ans);
}
return 0;
}