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.*;
import java.util.*;

public class D implements Runnable{
	public static void main (String[] args) {new Thread(null, new D(), "D", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		int n = fs.nextInt();
		int m = fs.nextInt();
		int[] a = fs.nextIntArray(n);
		int odd = 0;
		for(int i = 0; i < n; i++) {
			if(a[i] > 0) odd++;
		}
		if(odd == 0) {
			System.out.println("0");
			return;
		}

		ArrayList<Edge>[] adj = new ArrayList[n];
		for(int i = 0; i < n; i++) {
			adj[i] = new ArrayList<>();
		}
		int[] deg = new int[n];
		for(int i = 0; i < m; i++) {
			int u = fs.nextInt()-1, v = fs.nextInt()-1;
			adj[u].add(new Edge(i, u, v));
			adj[v].add(new Edge(i, v, u));
			deg[u]++;
			deg[v]++;
		}

		boolean[] inc = new boolean[m];
		ArrayDeque<Integer> completeFix = new ArrayDeque<>();
		Arrays.fill(inc, true);
		for(int i = 0; i < n; i++) {
//			System.out.println(i + " " + Arrays.toString(deg));
			if(a[i] == -1) continue;
			if(a[i]%2 != deg[i]%2) {
				//bad node gotta fix
				//first can it connect to a -1?
				//if so just remove that edge

				boolean[] has = new boolean[3];
				Edge[] hh = new Edge[3];
				for(Edge e : adj[i]) {
					if(deg[e.v] == 0) continue; //disconnected nodes cant be used.
					if(a[e.v]%2 != deg[e.v]%2) {
						inc[e.id] = false;
						deg[e.u]--;
						deg[e.v]--;
//						System.out.println("  X  " + e.v);
						has[1] = true;
						break;
					}

					else if(a[e.v] == -1) {
						if(deg[e.v] != 0) {
							has[0] = true;
							hh[0] = e;
						}
					}

					else {
						has[2] = true;
						hh[2] = e;
					}

				}
				

				if(has[1]) continue;

				//if we get here then we need to try and disconnect
				//from an already bad node

				if(has[0]) {
					Edge e = hh[0];
					deg[e.v]--;
					deg[e.u]--;
					inc[e.id] = false;
					continue;
				}


				//if we get here then we need to mess with a node that's already complete.
				//after we mess with the good one, we should enqueue that one and try to fix it.

				ArrayDeque<Integer> fix = new ArrayDeque<>();
				fix.add(i);
				
				if(has[2]) {
					Edge e = hh[2];
					deg[e.v]--;
					deg[e.u]--;
					inc[e.id] = false;
					completeFix.add(e.v);
				}

//				while(!fix.isEmpty()) {
//					int now = fix.poll();
//					for(Edge e : adj[now]) {
//						if(deg[e.v] == 0) continue; //disconnected
//						if(a[e.v] == -1) {
//							//good just remove that and we're done
//							deg[e.v]--;
//							deg[e.u]--;
//							inc[e.id] = false;
//							break;
//						}
//
//						//we'll just pick the first one we see.
//						//Shouldn't be wrong I think?
//
//
//						deg[e.v]--;
//						deg[now]--;
//						inc[e.id] = false;
//
//						if(deg[e.v]%2 != a[e.v]%2) {
//							fix.add(e.v);
//							break;
//						}
//
//					}
//				}

			}
		}
		
		while(!completeFix.isEmpty()) {
			int now = completeFix.poll();
			boolean[] has = new boolean[3];
			Edge[] hh = new Edge[3];
			for(Edge e : adj[now]) {
				if(deg[e.v] == 0) continue; //disconnected nodes cant be used.
				if(a[e.v]%2 != deg[e.v]%2) {
					inc[e.id] = false;
					deg[e.u]--;
					deg[e.v]--;
//					System.out.println("  X  " + e.v);
					has[1] = true;
					break;
				}

				else if(a[e.v] == -1) {
					if(deg[e.v] != 0) {
						has[0] = true;
						hh[0] = e;
					}
				}

				else {
					has[2] = true;
					hh[2] = e;
				}

			}
			

			if(has[1]) continue;

			//if we get here then we need to try and disconnect
			//from an already bad node

			if(has[0]) {
				Edge e = hh[0];
				deg[e.v]--;
				deg[e.u]--;
				inc[e.id] = false;
				continue;
			}


			//if we get here then we need to mess with a node that's already complete.
			//after we mess with the good one, we should enqueue that one and try to fix it.

			if(has[2]) {
				Edge e = hh[2];
				deg[e.v]--;
				deg[e.u]--;
				inc[e.id] = false;
				completeFix.add(e.v);
			}
		}

		boolean bad = false;
		for(int i = 0; i < n; i++) {
			if(a[i] == -1) continue;
			if(deg[i]%2 != a[i]%2) {
				bad = true;
				break;
			}
		}

//		System.out.println(Arrays.toString(deg));
		
		if(bad) {
			System.out.println(-1);
			return;
		}

		int res = 0;
		for(Boolean b : inc) {
			if(b) res++;
		}
		out.println(res);
		int pc = 0;
		for(int i = 0; i < m; i++) {
			if(!inc[i]) continue;
			if(pc > 0) out.print(" ");
			pc++;
			out.print(i+1);
		}
		out.println();


		out.close();
	}

	class Edge {
		int id, u, v;
		Edge (int a, int b, int c) {
			id = a;
			u = b;
			v = c;
		}
	}

	void sort (int[] a) {
		int n = a.length;
		for(int i = 0; i < 1000; i++) {
			Random r = new Random();
			int x = r.nextInt(n), y = r.nextInt(n);
			int temp = a[x];
			a[x] = a[y];
			a[y] = temp;
		}
		Arrays.sort(a);
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		public FastScanner() {
			try	{
				br = new BufferedReader(new InputStreamReader(System.in));
				//                br = new BufferedReader(new FileReader("testdata.out"));
				st = new StringTokenizer("");
			} catch (Exception e){e.printStackTrace();}
		}
		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception e) {e.printStackTrace();}
			return st.nextToken();
		}
		public int nextInt() {return Integer.parseInt(next());}
		public long nextLong() {return Long.parseLong(next());}
		public double nextDouble() {return Double.parseDouble(next());}

		public String nextLine() {
			String line = "";
			try {line = br.readLine();}
			catch (Exception e) {e.printStackTrace();}
			return line;
		}
		public Integer[] nextIntegerArray(int n) {
			Integer[] a = new Integer[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
		public char[] nextCharArray() {return nextLine().toCharArray();}
	}

}