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.awt.Point;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class B {

	static int N, M;
	static ArrayList<Point>[] G, T;
	static int[] Tree, val, d;
	static ArrayList<Integer> un;
	static TreeSet<Integer> res;
	static int ov;
	static void dfs(int u, int p) {
		if(d[u] == -1)
			ov = u;
		int curD = 1;
		if(p == -1) {
			curD--;
		}
		Tree[u] = p;
		for(Point nxt: G[u]) {
			int v = nxt.x;
			if(Tree[v] == -2) {
				curD++;
				T[u].add(nxt);
				dfs(v, u);
				res.add(nxt.y);
			}
		}

		if(d[u] != -1 && curD % 2 != d[u] %2) 
			un.add(u);

	}

	static int dfs2(int u, int p) {
		int ans = 0;
		for(Point nxt : T[u]) {
			int v = nxt.x;
			if(v != p) {
				int cur = dfs2(v, u);
				if(cur % 2 == 1)
					res.remove(nxt.y);
				ans += cur;
			}
		}
		return ans + val[u];
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		N = sc.nextInt();
		M = sc.nextInt();

		d = new int[N];
		G = new ArrayList[N];
		T = new ArrayList[N];
		res = new TreeSet<>();
		Tree = new int[N];
		int[] deg = new int[N];
		val = new int[N];
		for (int i = 0; i < N; i++)
			d[i] = sc.nextInt();


		for (int i = 0; i < N; i++) {
			G[i] = new ArrayList<>();
			T[i] = new ArrayList<>();
		}

		for (int i = 0; i < M; i++) {
			int f = sc.nextInt() - 1;
			int t = sc.nextInt() - 1;
			G[f].add(new Point(t, i));
			G[t].add(new Point(f, i));
			deg[f]++;
			deg[t]++;
		}

		Arrays.fill(Tree, -2);

		un = new ArrayList<>();
		ov = -1;
		dfs(0, -1);
		if(un.size() % 2 == 1 && ov != -1) 
			un.add(ov);

		if(un.size() % 2 != 0) {
			out.println(-1);
			out.flush();
			return;
		}


		G = null;


		for (int j = 0; j < un.size(); j++) {
			int x = un.get(j);
			val[x]++;
		}


		for (int i = 0; i < N; i++) {
			if(Tree[i] == -1)
				dfs2(i, -1);
		}
		out.println(res.size());
		for (int i : res) 
			out.println(i + 1);

		out.flush();
		out.close();
	}




	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
		public Scanner(String file) throws FileNotFoundException{	br = new BufferedReader(new FileReader(file));}


		public String next() throws IOException {
			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}
		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

	}

}

