3 2
1 0 1
1 2
2 3
 10 10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
6 7
8 3
6 4
4 2
9 2
5 10
9 8
10 7
5 1
6 2

2
1
2
 0

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _for(i,a,b) for(int i = (a);i < b;i ++)
#define _rep(i,a,b) for(int i = (a);i > b;i --)
#define INF 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define lowbit(x) ((x)&(-x))
#define mod 1000000007
#define MIKU 39
#define Design ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug() printf("Miku Check OK!\n")
#define MIKUCHAR "M"

#define maxn 300003
#define maxe 650003
struct G
{
	int n,m;
	int Next[maxe];
	int head[maxn];
	int ver[maxe];
	int val[maxe];
	int id[maxe];
	int tot;
	void clear(int x)
	{
		tot = 0;
		memset(head,0,(x+3)*sizeof(int));
	}
	void add(int x,int y,int w,int d)
	{
		ver[++tot] = y,Next[tot] = head[x],head[x] = tot,val[tot] = w,id[tot] = d;
	}
} g, t;

struct Djs
{
    int par[maxn];
    int high[maxn];
    Djs()
    {
		_for(i,1,maxn)
        {
            par[i] = i;
            high[i] = 0;
        }
    }
    int find(int x)
    {
        return par[x] == x ? x : par[x] = find(par[x]);
    }
    void unite(int x,int y)
    {
        x = find(x);
        y = find(y);
        if(x==y) return ;
        if(high[x]<high[y])
            par[x] = y;
        else
        {
            par[y] = x;
            if(high[x]==high[y])
                high[x] ++;
        }
    }
    bool same(int x,int y)
    {
        return find(x) == find(y);
    }
}MSTd1;

struct Kruskal
{
	struct edge
	{
		int u;
		int v;
		int id;
		ll w;
		bool operator < (edge b)
		{
			return w < b.w;
		}
	}; 
	vector<edge> e; 
	ll MSTval;
	void kruskal(const G &g)
	{
 		_for(x,1,g.n+1)
			for(int i = g.head[x]; i; i = g.Next[i])
				e.pb({x,g.ver[i],g.id[i],g.val[i]});
		sort(e.begin(),e.end());
		_for(i,0,e.size())
			if(!MSTd1.same(e[i].u,e[i].v))
			{
				MSTd1.unite(e[i].u,e[i].v);
				MSTval += e[i].w;
				t.add(e[i].u,e[i].v,MIKU,e[i].id);
				t.add(e[i].v,e[i].u,MIKU,e[i].id);
			}
	}
}k;
vector<int> ans;
int a[maxn];
int dfs(int x,int fa,int iid)
{
//	cout << x << endl;
	int cnt = ((a[x])==1)?1:0;
	for(int i = t.head[x]; i;i = t.Next[i])
	{
		int y = t.ver[i];
		int id = t.id[i];
		if(y==fa)	
			continue;
		cnt += dfs(y,x,id);
	}
	if(cnt&0x1)
		ans.pb(iid);
	return cnt;
}

int main()
{
	scanf("%d%d",&g.n,&g.m);
	int ok = 0, cnt = 0;
	_for(i,1,g.n+1)
	{
		scanf("%d",&a[i]);
		if(a[i]==1)
			cnt ++;
		else if(a[i]==-1)
			ok = 1;
	}
	if((cnt&0x1) && !ok)
	{
		printf("-1\n");
		return 0;
	}
	if(cnt&0x1)
	{
		_for(i,1,g.n+1)
			if(a[i]==-1)
				a[i] = 1;
	}
	_for(i,1,g.m+1)
	{
		int x, y;
		scanf("%d%d",&x,&y);
		g.add(x,y,1,i);
		g.add(y,x,1,i);
	}
	k.kruskal(g);
	dfs(1,-1,-1);
//	return 0;
	printf("%d\n",ans.size());
	for(auto p:ans)
	{
//		assert(p>=0);
		printf("%d ",p);
	}
	return 0;
}
