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 D841 {

	public static void main(String[] args) throws IOException {
		IO io = new IO(System.in);

		int n = io.nextInt();
		int m = io.nextInt();

		int[] tar = new int[n];
		int minus = -1;
		int nr_odd = 0;
		for (int i = 0; i < tar.length; i++) {
			tar[i] = io.nextInt();
			if (tar[i] == -1) {
				minus = i;
			} else if (tar[i] == 1) {
				nr_odd++;
			}
		}

		ArrayList<Integer>[] g = new ArrayList[n];
		for (int i = 0; i < g.length; i++) {
			g[i] = new ArrayList<>();
		}
		
		HashMap<Long,Integer> map = new HashMap<>();

		for (int i = 0; i < m; i++) {
			int u = io.nextInt() - 1;
			int v = io.nextInt() - 1;
			g[u].add(v);
			g[v].add(u);
			
			long a = Math.min(u, v);
			long b = Math.max(u, v);
			
			map.put(a*1000000+b,i+1);
		}

		if (nr_odd % 2 == 1 && minus == -1) {
			// No -1 and odd number of odd degree vertices: impossible
			io.println(-1);
			io.close();
			System.exit(0);
		}

		// select root: pick a -1, or if none exist pick vertex 0
		int root = minus;
		if (root == -1)
			root = 0;

		int[] parent = new int[n];
		Arrays.fill(parent, -1);
		parent[root] = -2;

		Stack<Integer> st = new Stack<>();
		Queue<Integer> q = new LinkedList<>();
		q.add(root);
		st.add(root);

		while (!q.isEmpty()) {
			int cur = q.poll();
			for (int v : g[cur]) {
				if (parent[v] == -1) {
					parent[v] = cur;
					q.add(v);
					st.add(v);
				}
			}
		}

		ArrayList<E> edges = new ArrayList<>();

		while (!st.isEmpty()) {
			int cur = st.pop();
			if (tar[cur] == 1) {
				// cur must have an extra edge
				long a = Math.min(cur, parent[cur]);
				long b = Math.max(cur, parent[cur]);
				
				edges.add(new E(a, b));
				tar[cur] = 0;
				if (tar[parent[cur]] == 0) {
					tar[parent[cur]] = 1;
				} else if (tar[parent[cur]] == 1) {
					tar[parent[cur]] = 0;
				}
			}
		}
		
		io.println(edges.size());
		
		for (E e : edges) {
			long a = e.u;
			long b = e.v;
			
			io.println(map.get(a*1000000+b));
		}

		io.close();
	}

	static class E implements Comparable<E> {
		long u, v;

		E(long _u, long _v) {
			u = _u;
			v = _v;
		}
		
		public int compareTo(E o) {
			if (Long.compare(this.u, o.u)!=0) {
				return Long.compare(this.u, o.u);
			} else {
				return Long.compare(this.v, o.v);
			}
		}
		
		public String toString() {
			return String.format("(%d %d)", u, v);
		}
		
	}

	static class IO extends PrintWriter {
		static BufferedReader r;
		static StringTokenizer t;

		public IO(InputStream i) {
			super(new BufferedOutputStream(System.out));
			r = new BufferedReader(new InputStreamReader(i));
			t = new StringTokenizer("");
		}

		public String next() throws IOException {
			while (!t.hasMoreTokens()) {
				t = new StringTokenizer(r.readLine());
			}
			return t.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
	}
}