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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        int n;
        int m;
        List<TaskB.Edge>[] g;
        int[] got;
        int[] d;
        List<TaskB.Edge> answer;

        public void solve(int testNumber, FastReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            g = new List[n];
            got = new int[n];
            d = in.nextIntArray(n);
            answer = new ArrayList<>();
            ArrayUtils.fill(got, -1);
            for (int i = 0; i < n; ++i) g[i] = new ArrayList<>();
            for (int i = 0; i < m; ++i) {
                int u = in.nextInt() - 1;
                int v = in.nextInt() - 1;
                g[u].add(new TaskB.Edge(v, i + 1));
                g[v].add(new TaskB.Edge(u, i + 1));
            }
            int root = 0;
            for (int i = 0; i < n; ++i) {
                if (d[i] < 0) {
                    root = i;
                    break;
                }
            }
            dfs(root);
            if (d[root] >= 0 && d[root] != got[root]) {
                out.println(-1);
            } else {
                out.println(answer.size());
                for (TaskB.Edge aa : answer) out.println(aa.index);
            }
        }

        private void dfs(int cur) {
            got[cur] = 0;
            for (TaskB.Edge edge : g[cur]) {
                if (got[edge.to] < 0) {
                    dfs(edge.to);
                    if (d[edge.to] >= 0 && d[edge.to] != got[edge.to]) {
                        answer.add(edge);
                        got[edge.to] ^= 1;
                        got[cur] ^= 1;
                    }
                }
            }
        }

        static class Edge {
            int to;
            int index;

            public Edge(int to, int index) {
                this.to = to;
                this.index = index;
            }

        }

    }

    static class ArrayUtils {
        public static void fill(int[] array, int value) {
            Arrays.fill(array, value);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        private int pread() {
            if (pnumChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= pnumChars) {
                curChar = 0;
                try {
                    pnumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (pnumChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = pread();
            while (isSpaceChar(c))
                c = pread();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = pread();
            }
            int res = 0;
            do {
                if (c == ',') {
                    c = pread();
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = pread();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}

