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, int l) {
		if(d[u] == -1)
			ov = u;
		int curD = 1;
		if(p == -1) {
			curD--;
		}
		L[u] = l;
		Tree[u] = p;
		for(Point nxt: G[u]) {
			int v = nxt.x;
			if(Tree[v] == -2) {
				curD++;
				T[u].add(nxt);
				dfs(v, u, l + 1);
				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];
		ArrayList<ArrayList<Integer>> list = new ArrayList<>();
		res = new TreeSet<>();
		Tree = new int[N];
		L = 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);
		for (int i = 0; i < N; i++) {
			if(Tree[i] == -2) {
				un = new ArrayList<>();
				ov = -1;
				dfs(i, -1, 0);
				if(un.size() % 2 == 1 && ov != -1) 
					un.add(ov);

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


		for (int i = 0; i < list.size(); i++) {
			ArrayList<Integer> cur = list.get(i);

			for (int j = 0; j < cur.size(); j+=2) {
				int x = cur.get(j);
				int y = cur.get(j + 1);
				int lca = query(x, y);
				val[x]++;
				val[y]++;
				val[lca]-=2;
			}
		}

		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 int L[], P[][];			// P[i][j] --> the 2^j th ancestor of node i

	static void preprocessParents()	// O(n log n)
	{
		int k = 0; while(1<<k+1 < N) ++k;		// max parent = floor(log2(N - 1))

		P = new int[N][k + 1];

		for(int i = 0; i < N; i++)
			Arrays.fill(P[i], -1);

		// base case: direct parents
		for(int i = 0; i < N; ++i)
			P[i][0] = Tree[i];					// T[root] = -1				

		for(int j = 1; j <= k; j++)			
			for(int i = 0; i < N; i++)
				if(P[i][j-1] != -1)
					P[i][j] = P[P[i][j-1]][j-1];
	}

	static int query(int p, int q)		// O(log n)
	{
		//if p is situated on a higher level than q, swap them
		if (L[p] < L[q]) { p ^= q; q ^= p; p ^= q; }

		//find largest k such that 2^k is a parent of p
		int k = 0;
		while(1<<k+1 <= L[p])
			++k;

		//find the ancestor of p situated on the same level with q
		for (int i = k; i >= 0; --i)
			if (L[p] - (1<<i) >= L[q])
				p = P[p][i];

		if (p == q)
			return p;

		//go up to lowest (non-common) ancestors for p and q
		for (int i = k; i >= 0; --i)
			if (P[p][i] != -1 && P[p][i] != P[q][i])
			{
				p = P[p][i]; q = P[q][i];
			}

		return P[p][0];
	} 

	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);
		}

	}

}

