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 boolean[] oddAndCounted;
		public void solve(int testNumber, FastReader sc, PrintWriter out) {
			int N = sc.nextInt();
			int M = sc.nextInt();
			d_i = new int[N+1];
			adjList = new ArrayList<>();
			for(int i = 0; i <= N; i++) {
				adjList.add(new ArrayList<>());
			}
			Map<tup, Integer> edges = new HashMap<>();
			
			for(int i = 1; i <= N; i++) {
				d_i[i] = sc.nextInt();
			}
			
			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);
				if(edges.containsKey(new tup(U, V, 0)))
					System.out.println("CLARIFICATION");
				edges.put(new tup(U, V, 0), m);
				edges.put(new tup(V, U, 0), m);
			}
			
			
			// If this works, each odd node has a route to another odd node or an unclassified node.
			// BFS from each "odd" node or each "unclassified" node, maintaining parents.
			// If it hits a visited node, trace parents to confirm that route.
			
			oddAndCounted = new boolean[N+1];
			int[] parent = new int[N+1];
			int[] visitedBy = new int[N+1];
			Queue<tup> q = new LinkedList<>();
			for(int i = 1; i <= N; i++) {
				if(d_i[i] == 1) {
					q.add(new tup(i, i, 0));
				}
			}
			
			List<tup> sol = new ArrayList<>();
			while(q.size() > 0) {
				tup t = q.poll();
				//System.out.println(t);
				
				if(oddAndCounted[t.b])
					continue;
				
				if(d_i[t.a] == -1 && !oddAndCounted[t.b]) {
					oddAndCounted[t.b] = true;
					while(parent[t.c] != 0) {
						sol.add(new tup(t.c, parent[t.c], 0));
						t.c = parent[t.c];
					}
					sol.add(new tup(t.a, t.c, 0));
					continue;
				}
				
				if(visitedBy[t.a] == t.b) {
					continue;
				}
				
				if(visitedBy[t.a] != 0 && !oddAndCounted[visitedBy[t.a]]) {
					oddAndCounted[t.b]= true;
					oddAndCounted[visitedBy[t.a]]= true;
					
					int a = t.a;
					while(parent[a]!=0) {
						sol.add(new tup(a, parent[a], 0));
						a = parent[a];
					}
					
					parent[t.a] = t.c;
					a = t.a;
					while(parent[a]!= 0) {
						sol.add(new tup(a, parent[a], 0));
						a = parent[a];
					}
					visitedBy[t.a] = t.b;
					continue;
				}
				
				visitedBy[t.a] = t.b; 
				parent[t.a] = t.c; 
				for(int each: adjList.get(t.a)) {
					if(each != parent[t.a]) {
						q.add(new tup(each, t.b, t.a));
					}
				}
			}
					
			for(int i = 1; i < N+1; i++) {
				if(d_i[i] == 1 && !oddAndCounted[i]) {
					out.println(-1);
					return;
				}
			}
			
			out.println(sol.size());
			for(tup each: sol) {
				out.println(edges.get(new tup(each.a, each.b, 0)));
			}

		}
	}
	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, c;
		tup(int a,int b, int c){
			this.a=a;
			this.b=b;
			this.c=c;
		}
		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 + " " + c;
	    }
	}
	
	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;
		}
	}

}