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

public class b429 implements Runnable{
	
    public static void main(String[] args) {
    	try{
            new Thread(null, new b429(), "process", 1<<26).start();
        }
        catch(Exception e){
            System.out.println(e);
        }
    }
	public void run() {
		FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		//PrintWriter out = new PrintWriter("file.out");
		Task solver = new Task();
		//int t = scan.nextInt();
		int t = 1;
		for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
		out.close();
	}

	static class Task {
		static final int inf = Integer.MAX_VALUE;
		static int[] d_i;
		static List<List<Integer>> adjList;
		
		static Set<tup> ans = new HashSet<>();
		static boolean[] visited;
		
		public void solve(int testNumber, FastReader sc, PrintWriter out) {
			int N = sc.nextInt();
			int M = sc.nextInt();
			d_i = new int[N+1];
			ans = new HashSet<>();
			adjList = new ArrayList<>();
			for(int i = 0; i <= N; i++) {
				adjList.add(new ArrayList<>());
			}
			Map<tup, Integer> edges = new HashMap<>();
			
			int start = 1;
			for(int i = 1; i <= N; i++) {
				d_i[i] = sc.nextInt();
				if(d_i[i] == -1)
					start = i;
			}
			
			for(int m = 1; m <= M; m++) {
				int U = sc.nextInt();
				int V = sc.nextInt();
				adjList.get(U).add(V);
				adjList.get(V).add(U);
				edges.put(new tup(U, V), m);
				edges.put(new tup(V, U), m);
			}
			
			// fill in the number of odd in each branch for each node
			//System.out.println(start);
			visited = new boolean[N+1];
			if(d_i[start] == -1) {
				drawEdges(start);
			} else {
				if(drawEdges(start)) {
					out.println(-1);
					out.close();
					System.exit(0);
				}
			}
			
			//System.out.println(ans);
			out.println(ans.size());
			for(tup each: ans) {
				out.println(edges.get(each));
			}
		}
				
		public static boolean drawEdges(int node) {
			visited[node] = true;

			boolean odd = false;
			for(int each: adjList.get(node)) {
				if(!visited[each]) {
					if(drawEdges(each)) {
						ans.add(new tup(each, node));
						odd = !odd;
					}
				}
			}
			if(d_i[node] == 1) {
				odd = !odd;
			}
			return odd;
		}
		
	}
	static long binpow(long a, long b, long m) {
		a %= m;
		long res = 1;
		while (b > 0) {
			if ((b & 1) == 1)
				res = res * a % m;
			a = a * a % m;
			b >>= 1;
		}
		return res;
	}
	static void sort(int[] x){
		shuffle(x);
		Arrays.sort(x);
	}
	static void sort(long[] x){
		shuffle(x);
		Arrays.sort(x);
	}
	static class tup implements Comparable<tup>, Comparator<tup>{
		int a, b;
		tup(int a,int b){
			this.a=a;
			this.b=b;
		}
		public tup() {
		}
		@Override
		public int compareTo(tup o){
			return Integer.compare(o.b,b);
		}
		@Override
		public int compare(tup o1, tup o2) {
			return Integer.compare(o1.b, o2.b);
		}
		
		@Override
	    public int hashCode() {
			return Objects.hash(a, b);
	    }
 
	    @Override
	    public boolean equals(Object obj) {
	    	if (this == obj)
                return true;
	    	if (obj == null)
                return false;
	    	if (getClass() != obj.getClass())
                return false;
	    	tup other = (tup) obj;
	    	return a==other.a && b==other.b;
	    }
	    
	    @Override
	    public String toString() {
	    	return a + " " + b;
	    }
	}
	
	static void shuffle(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static void shuffle(long[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}