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

#include <bits/stdc++.h>
using namespace std;
inline int leer() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m, d[300010], cabeza[300010], vis[300010], cnt, tot, ans[300010];
struct edge {
  int to;
  int po;
  int next;
} e[300010 * 2];
bool dfs(int u) {
  vis[u] = 1;
  int pd = 0;
  for (int i = cabeza[u]; i; i = e[i].next) {
    if (vis[e[i].to]) continue;
    int flag = dfs(e[i].to);
    pd ^= flag;
    if (flag) ans[++cnt] = e[i].po;
  }
  if (pd == d[u] || d[u] == -1) return false;
  return true;
}
int main() {
  n = leer();
  m = leer();
  int root = 0;
  for (int i = 1; i <= n; i++) {
    d[i] = leer();
    if (d[i] == -1) root = i;
  }
  if (!root) root = 1;
  for (int i = 1; i <= m; i++) {
    int u = leer(), v = leer();
    e[++tot].to = v;
    e[tot].next = cabeza[u];
    cabeza[u] = tot;
    e[tot].po = i;
    e[++tot].to = u;
    e[tot].next = cabeza[v];
    cabeza[v] = tot;
    e[tot].po = i;
  }
  if (dfs(root))
    puts("-1");
  else {
    printf("%d\n", cnt);
    for (int i = 1; i <= cnt; i++) printf("%d\n", ans[i]);
  }
}
