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

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;


import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.TreeSet;


public final class CF_429_D{

	static boolean verb=true;
	static void log(Object X){if (verb) System.err.println(X);}
	static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}}

	static void logWln(Object X){if (verb) System.err.print(X);}
	static void info(Object o){	System.out.println(o);}
	static void output(Object o){outputWln(""+o+"\n");	}
	static void outputWln(Object o){try {out.write(""+ o);} catch (Exception e) {}}

	static int MX=Integer.MAX_VALUE;


	// Global vars
	static BufferedWriter out;
	static InputReader reader;

	static long mod=1000000007;

	static int[][] friends;
	static int[][] edges;


	static int[] d;
	static int[] x,y;
	static ArrayList<Integer> target;



	static void readGraph(int n,int m) throws Exception {


		log("read graph");
		friends=new int[n][];
		edges=new int[n][];

		x=new int[m];
		y=new int[m];
		int[] p=new int[n];

		int u=0;
		int v=0;
		for (int i=0;i<m;i++){


			u=reader.readInt()-1;
			v=reader.readInt()-1;

			if( Math.abs(d[u])==1 && Math.abs(d[v])==1){
				target=new ArrayList<Integer>();
				target.add(i);
				//log("detecting good case");
			}
			
			x[i]=u;
			p[u]++;
			y[i]=v;
			p[v]++;

		}




		for (int i=0;i<n;i++){
			friends[i]=new int[p[i]];
			edges[i]=new int[p[i]];

			//friends[i]=new int[1];
		}

		for (int i=0;i<m;i++){
			u=x[i];
			v=y[i];
			friends[u][--p[u]]=v;
			friends[v][--p[v]]=u;
			edges[u][p[u]]=i;
			edges[v][p[v]]=i;


		}



	}



	static void process() throws Exception {



		out = new BufferedWriter(new OutputStreamWriter(System.out));
		reader=new InputReader(System.in);


		int n=reader.readInt();
		int m=reader.readInt();

		d=new int[n];
		for (int i=0;i<n;i++){
			d[i]=reader.readInt();

		}

		readGraph(n,m);

		int[] visited=new int[n];
		int[][] stack=new int[n][2];
		int[] used=new int[m];
		int[] fedge=new int[n];
		int[] fnode=new int[n];
		
		int time=1;
		int st=0;
		// we start with 0 node
		// we grow and stop when we find some 1..
		// chiantos
		// faut stocker l'edge parcourru..
		// bon yen a marred
		int[] from=new int[n];
		int[] list=new int[2];
		int sz;
		int[] h=new int[n];
		if (target==null){
			loop:for (int i=0;i<n;i++){
				if (d[i]==0){
					time++;
					sz=0;
					st=0;
					stack[st][0]=i;
					stack[st][1]=0;
					st++;
					visited[i]=time;
					fnode[i]=-1;
					fedge[i]=-1;
					h[i]=0;
					int cnt=0;
					while (st>0){

						int u=stack[st-1][0];
						int cur=stack[st-1][1];

						if (cur<friends[u].length){
							int v=friends[u][cur];
							int ed=edges[u][cur];
							stack[st-1][1]++;
							if (used[ed]<time){ // don't do the same edge twice

								if (visited[v]<time){
									if (d[v]==0){
										stack[st][0]=v;
										stack[st][1]=0;
										used[ed]=time;
										st++;
									} else {
										if (sz<2)
											list[sz++]=v;
										if (sz==2){
											int uu=list[0];
											int vv=list[1];
											target=new ArrayList<Integer>();
											while (h[vv]>h[uu]){
												target.add(fedge[vv]);
												vv=fnode[vv];
											}
											while (h[uu]>h[vv]){
												target.add(fedge[uu]);
												uu=fnode[uu];
											}
											while (uu!=vv){
												target.add(fedge[vv]);
												vv=fnode[vv];
												target.add(fedge[uu]);
												uu=fnode[uu];
												
											}
											
											break loop;
										}
									}
									fedge[v]=edges[u][cur];
									fnode[v]=u;
									visited[v]=time;
									h[v]=h[u+1];
								} else {
									if (d[v]==0){
										// we have a loop
										target=new ArrayList<Integer>();
										target.add(edges[u][cur]);
										int vv=v;
										int uu=u;
										while (h[vv]>h[uu]){
											target.add(fedge[vv]);
											vv=fnode[vv];
										}
										while (h[uu]>h[vv]){
											target.add(fedge[uu]);
											uu=fnode[uu];
										}
										while (uu!=vv){
											target.add(fedge[vv]);
											vv=fnode[vv];
											target.add(fedge[uu]);
											uu=fnode[uu];
											
										}
										Collections.sort(target);
										break loop;
									}
									
									
								}

							}
						} else {
							// remove node from stack
							st--;
						}
					}
				}
			}
		}
		
		if (target==null){
			output("-1");
		} else {
			output(target.size());
			for (int x:target){
				outputWln((x+1)+" ");
			}
			output("");
		}


		try {
			out.close();
		}
		catch (Exception e){}


	}


	public static void main(String[] args) throws Exception {
		process();

	}

	static final class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		private int read() throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read(buf);
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}


		public final String readString() throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res=new StringBuilder();
			do {
				res.append((char)c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final int readInt() throws IOException {
			int c = read();
			boolean neg=false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d=(char)c;
			//log("d:"+d);
			if (d=='-') {
				neg=true;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			//log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		public final long readLong() throws IOException {
			int c = read();
			boolean neg=false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d=(char)c;
			//log("d:"+d);
			if (d=='-') {
				neg=true;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			//log("res:"+res);
			if (neg)
				return -res;
			return res;

		}




		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	}


}