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.util.*;
import java.io.*;
import java.math.*;
 
public class Main{
    static BufferedReader br = 
            new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter bw = 
            new BufferedWriter(new OutputStreamWriter(System.out));
    static StringTokenizer st;
    
    static int[] d;
    
    public static void main(String args[]) throws IOException{
    	Scanner sc = new Scanner(System.in);
    	int n, m, s, e, i, c = 0;
    	n = sc.nextInt();
    	m = sc.nextInt();
    	d = new int[n];
    	for(i = 0; i < n; i++) d[i] = sc.nextInt();
    	Edge[] edges = new Edge[m];
    	for(i = 0; i < m; i++){
    		s = sc.nextInt()-1;
    		e = sc.nextInt()-1;
    		edges[i] = new Edge(s, e, i+1);
    	}
    	Arrays.sort(edges);
    	int[] cnt = new int[n];
    	int[] list = new int[m];
    	for(i = 0; i < m; i++){
    		s = edges[i].s;
    		e = edges[i].e;
    		if(d[s] == -1){
    			if(d[e] == -1) continue;
    			if(d[e] == cnt[e]%2) continue;
    			else{
    				cnt[e]++;
    				list[c++] = edges[i].idx;
    			}
    		}else if(d[s] == 0){
    			if(d[e] == -1){
    				if(d[s] == cnt[s]%2) continue;
        			else{
        				cnt[s]++;
        				list[c++] = edges[i].idx;
        			}
    			}else if(d[e] == 0){
    				if(cnt[s]%2 == 1 && cnt[e]%2 == 1){
    					cnt[s]++;
    					cnt[e]++;
        				list[c++] = edges[i].idx;
    				}
    			}else{
    				if(cnt[s]%2 == 1 && cnt[e]%2 == 0){
    					cnt[s]++;
    					cnt[e]++;
        				list[c++] = edges[i].idx;
    				}
    			}
    		}else{
    			if(d[e] == -1){
    				if(d[s] == cnt[s]%2) continue;
        			else{
        				cnt[s]++;
        				list[c++] = edges[i].idx;
        			}
    			}else if(d[e] == 0){
    				if(cnt[s]%2 == 0 && cnt[e]%2 == 1){
    					cnt[s]++;
    					cnt[e]++;
        				list[c++] = edges[i].idx;
    				}
    			}else{
    				if(cnt[s]%2 == 0 && cnt[e]%2 == 0){
    					cnt[s]++;
    					cnt[e]++;
        				list[c++] = edges[i].idx;
    				}
    			}
    		}
    	}
    	for(i = 0; i < n; i++){
    		if(d[i] == -1) continue;
    		if(d[i] != cnt[i]%2){
    			System.out.println("-1");
    			return;
    		}
    	}
    	bw.write(c+"\n");
    	Arrays.sort(list, 0, c);
    	for(i = 0; i < c; i++) bw.write(list[i]+"\n");
    	bw.close();
    }
    
    static class Edge implements Comparable<Edge>{
    	
    	int s, e, idx;
    	
    	Edge(int S, int E, int IDX){
    		s = S; e = E; idx = IDX;
    	}
    	
    	public int compareTo(Edge E){
    		int f1 = 0, f2 = 0;
    		if(d[s] == -1 || d[e] == -1) f1 = -1;
    		else if(d[s] == d[e]) f1 = 0;
    		else f1 = 1;
    		if(d[E.s] == -1 || d[E.e] == -1) f2 = -1;
    		else if(d[E.s] == d[E.e]) f2 = 0;
    		else f2 = 1;
    		if(f1 == f2) return 0;
    		else return (f1 < f2) ? -1 : 1;
    	}
    }
}