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<Set<tup>> adjList;
		
		static Set<tup> ans = new HashSet<>();
		static int numOdd = 0;
		
		
		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 HashSet<>());
			}
			Map<tup, Integer> edges = new HashMap<>();
			
			for(int i = 1; i <= N; i++) {
				d_i[i] = sc.nextInt();
				if(d_i[i] == 1)
					numOdd++;
			}
			
			for(int m = 1; m <= M; m++) {
				int U = sc.nextInt();
				int V = sc.nextInt();
				adjList.get(U).add(new tup(V, 0));
				adjList.get(V).add(new tup(U, 0));
				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
			visited = new boolean[N+1];
			findOdd(1, 0);
			
			//System.out.println(adjList);
			leftOdd = new HashSet<>();

			// pair all odds in all branches, drawing edges for each pair
			visited = new boolean[N+1];
			drawEdges(1);
			
			//System.out.println(ans);
			//System.out.println(leftOdd);
			visited = new boolean[N+1];
			for(int each: leftOdd) {
				if(!dfs(each, -1)) {
					out.println("-1");
					out.close();
					System.exit(0);
				}
			}
			//System.out.println("SOL" + ans);
			out.println(ans.size());
			for(tup each: ans) {
				out.println(edges.get(each));
			}
		}
		
		static Set<Integer> leftOdd;
		public static boolean dfs(int node, int parent) {
			if(visited[node])
				return false;
			visited[node] = true;
			if(parent != -1 && d_i[node] == 1)
				return false;
			if(d_i[node] == -1) {
				ans.add(new tup(Math.min(node, parent), Math.max(node, parent)));
				return true;
			}
			boolean b = false;
			for(tup each: adjList.get(node)) {
				if(dfs(each.a, node)) {
					b = true;
				}
			}
			if(b) {
				if(parent != -1)
					ans.add(new tup(Math.min(node, parent), Math.max(node, parent)));
				return true;
			}
			return false;
		}
				
		public static void drawEdges(int node) {
			visited[node] = true;

			int lastOdd = -1;
			for(tup each: adjList.get(node)) {
				if(each.b % 2 == 1) {
					if(lastOdd == -1)
						lastOdd = each.a;
					else {
						ans.add(new tup(Math.min(lastOdd, node), Math.max(lastOdd, node)));
						ans.add(new tup(Math.min(each.a, node), Math.max(each.a, node)));
						lastOdd = -1;
					}
				}
			}
			
			if(lastOdd != -1 && d_i[node] == 1) {
				ans.add(new tup(Math.min(lastOdd, node), Math.max(lastOdd, node)));
			} else if (lastOdd != -1)
				leftOdd.add(lastOdd);
			for(tup each: adjList.get(node)) {
				if(!visited[each.a]) {
					drawEdges(each.a);
				}
			}
			
			if(d_i[node] == 1 && adjList.get(node).size() == 0)
				leftOdd.add(node);
		}
		
		
		
		static boolean[] visited;
		// returns the number of odd nodes
		public static int findOdd(int node, int parent) {
			int total = 0;
			visited[node] = true;
			for(tup each: adjList.get(node)) {
				if(!visited[each.a]) {
					each.b = findOdd(each.a, node);
					total += each.b;
				} 
			}
			
			if(node != 1) {
				adjList.get(node).remove(new tup(parent, 0));
				adjList.get(node).add(new tup(parent, numOdd - total - ((d_i[node] == 1) ? 1 : 0)));
			}
			
			return (d_i[node] == 1) ? total+1 : total;
		}
	}
	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;
		}
	}

}