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

/*
* Filename:    d.cpp
* Created:     Friday, August 18, 2017 11:31:48 PM
* Author:      crazyX
* More:
*
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define clr(a,b) (memset(a,b,sizeof(a)))
#define y0 y3487465
#define y1 y8687969
#define fastio std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int INF=1e9+7;
const int maxn=3e5+7;
int n,m,T,d[maxn];
vector<int> g[maxn];
struct edge{
	int u,v,id;
	bool operator == (const edge &e1){
		return u==e1.u&&v==e1.v;
	}
	void in(int i){
		scanf("%d%d",&u,&v);
		if(u>v)swap(u,v);
		id=i;
	}
}e[maxn],e2[maxn];
bool cmp(edge e1, edge e2){
	if(e1.u==e2.u)return e1.v<e2.v;
	return e1.u<e2.u;
}
int cnt[maxn], idx[maxn], rd[maxn];
int main()
{
#ifdef AC
	freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	clr(cnt,0);clr(idx,0);clr(rd,0);
	for (int i = 1; i <= n; i += 1){
		scanf("%d",d+i);
	}
	for (int i = 0; i < m; i += 1)e[i].in(i+1);
	sort(e,e+m,cmp);
	m=unique(e,e+m)-e;
	vector<int> ans;
	
	for (int i = 0; i < m; i += 1){
		int u = e[i].u,v=e[i].v;
		if(d[u]==-1){
			rd[v]=e[i].id;
		}
		if(d[v]==-1){
			rd[u]=e[i].id;
		}
		if(d[u]!=1&&d[v]!=1)continue;
		if(d[u]==1&&d[v]==1){
			ans.pb(e[i].id);
			d[u]=d[v]=0;
		}else{
			if(d[v]==1)swap(u,v);
			//d[u]=1
			if(d[v]==0){
				if(cnt[v]==0){
					cnt[v]=e[i].id;
					idx[v]=u;
				}else{
					ans.pb(cnt[v]);
					d[idx[v]]=0;
					
					ans.pb(e[i].id);
					d[u]=0;
					
					cnt[v]=0;
				}
			}else{//d[v]=-1
				rd[u]=e[i].id;
			}
		}
	}
	for (int i = 1; i <= n; i += 1){
		if(cnt[i]!=0){
			if(rd[i]!=0){
				ans.pb(cnt[i]);
				d[idx[i]]=0;
				
				ans.pb(rd[i]);
				cnt[i]=0;
			}else return 0*puts("-1");
		}
	}
	
	for (int i = 1; i <= n; i += 1){
		if(d[i]==1){
			if(rd[i]==0)return 0*puts("-1");
			else ans.pb(rd[i]);
			
		}
	}

	printf("%d\n",SZ(ans));
	for (int i = 0; i < SZ(ans); i += 1)
		printf("%d ",ans[i]);
	return 0;
}