#include <bits/stdc++.h>
using namespace std;
const int N = 300009;
int head[N], cnt, n, m, deg[N], flag, all, fa[N], x[N], y[N], ans[N], siz[N],
    Ans;
struct Edge {
  int nxt, to, w;
} g[N * 2];
void add(int from, int to, int w) {
  g[++cnt].nxt = head[from];
  g[cnt].to = to;
  g[cnt].w = w;
  head[from] = cnt;
}
void init() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &deg[i]);
    if (deg[i] == -1)
      flag = 1;
    else
      all += deg[i];
    fa[i] = i;
  }
  for (int i = 1; i <= m; i++) scanf("%d %d", &x[i], &y[i]);
}
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void dfs(int x, int fa, int k) {
  siz[x] = deg[x];
  for (int i = head[x]; i; i = g[i].nxt) {
    int v = g[i].to;
    if (v == fa) continue;
    dfs(v, x, g[i].w);
    siz[x] += siz[v];
  }
  if (siz[x] & 1) ans[k] = 1;
}
void work() {
  if (!flag && (all & 1)) {
    puts("-1");
    return;
  }
  for (int i = 1; i <= n; i++)
    if (deg[i] == -1)
      if (all & 1)
        all++, deg[i] = 1;
      else
        deg[i] = 0;
  for (int i = 1; i <= m; i++) {
    int A = find(x[i]), B = find(y[i]);
    if (A != B) fa[B] = A, add(x[i], y[i], i), add(y[i], x[i], i);
  }
  for (int i = head[1]; i; i = g[i].nxt) dfs(g[i].to, 1, g[i].w);
  for (int i = 1; i <= m; i++) Ans += ans[i];
  printf("%d\n", Ans);
  for (int i = 1; i <= m; i++)
    if (ans[i]) printf("%d\n", i);
}
int main() {
  init();
  work();
  return 0;
}
