#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> vt;
vector<int> dap;
int n, m;
int visited[300010];
int cst[300010];
int qry[300010][2];
int dfs(int here) {
  visited[here] = 1;
  int ret = cst[here];
  for (int i = 0; i < vt[here].size(); i++) {
    int id = vt[here][i];
    int next = qry[id][0] ^ qry[id][1] ^ here;
    if (!visited[next]) {
      if (dfs(next)) {
        ret ^= 1;
        dap.push_back(id);
      }
    }
  }
  return ret;
}
int main() {
  scanf("%d %d", &n, &m);
  vt.resize(n + 1);
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &cst[i]);
    if (cst[i] == -1) continue;
    sum ^= cst[i];
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &qry[i][0], &qry[i][1]);
    vt[qry[i][0]].push_back(i);
    vt[qry[i][1]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (cst[i] != -1) continue;
    if (sum & 1) {
      cst[i] = 1;
      sum = 0;
    } else
      cst[i] = 0;
  }
  if (sum & 1) {
    puts("-1");
    return 0;
  }
  dfs(1);
  printf("%d\n", dap.size());
  for (int i = 0; i < dap.size(); i++) printf("%d ", dap[i] + 1);
}
