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.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

/*
 * public class _841D {
 * 
 * }
 */

public class _841D {

  class node {
    int v;
    int en;

    public node(int v, int en) {
      super();
      this.v = v;
      this.en = en;
    }


  }

  public void solve() throws FileNotFoundException {
    InputStream inputStream = System.in;

    InputHelper inputHelper = new InputHelper(inputStream);

    PrintStream out = System.out;

    // actual solution
    int n = inputHelper.readInteger();
    int m = inputHelper.readInteger();

    int[] d = new int[n];

    for (int i = 0; i < n; i++) {
      d[i] = inputHelper.readInteger();

      if (d[i] == -1) {
        r = i;
      }
    }

    List[] g = new List[n];

    for (int i = 0; i < n; i++) {
      g[i] = new ArrayList<node>();
    }

    for (int i = 0; i < m; i++) {
      int u = inputHelper.readInteger();
      int v = inputHelper.readInteger();

      u--;
      v--;

      g[u].add(new node(v, i));
      g[v].add(new node(u, i));
    }

    boolean[] onStack = new boolean[n];
    boolean[] vis = new boolean[n];
    int[] state = new int[n];

    int fd = dfs(r, d, g, onStack, vis, state);

    if (fd == 1 && d[r] != -1) {
      System.out.println("-1");
    } else {

      System.out.println(m - ans.size());

      for (int i = 0; i < m; i++) {
        if (!ans.contains(i)) {
          System.out.print((i + 1) + " ");
        }
      }
    }
    // end here
  }

  int r = 0;
  Set<Integer> ans = new HashSet<Integer>();
  Set<node> rv = new HashSet<node>();

  int dfs(int u, int[] d, List[] g, boolean[] s, boolean[] vis, int[] state) {
    s[u] = true;
    vis[u] = true;

    int cd;

    if ((g[u].size() % 2 == d[u]) || d[u] == -1) {
      cd = 0;
    } else {
      cd = 1;
    }

    for (int i = 0; i < g[u].size(); i++) {
      node nv = (node) g[u].get(i);

      int v = nv.v;

      if (!s[v] && !vis[v]) {

        if (u == r) {
          rv.add(nv);
        }
        int sd = dfs(v, d, g, s, vis, state);

        if (sd == 1) {
          ans.add(nv.en);

          cd = 1 - cd;
        }
      }
    }

    s[u] = false;

    return state[u] = cd;
  }

  public static void main(String[] args) throws FileNotFoundException {
    (new _841D()).solve();
  }

  class InputHelper {
    StringTokenizer tokenizer = null;
    private BufferedReader bufferedReader;

    public InputHelper(InputStream inputStream) {
      InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
      bufferedReader = new BufferedReader(inputStreamReader, 16384);
    }

    public String read() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          String line = bufferedReader.readLine();
          if (line == null) {
            return null;
          }
          tokenizer = new StringTokenizer(line);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }

      return tokenizer.nextToken();
    }

    public Integer readInteger() {
      return Integer.parseInt(read());
    }

    public Long readLong() {
      return Long.parseLong(read());
    }
  }
}
