#include <bits/stdc++.h>
const int MS = 3e5 + 5;
int n, m, d[MS], p[MS], sum[MS];
int head[MS], ecnt = 1;
bool ans[MS];
struct Edge {
  int next, to, id;
} e[MS * 2];
void addedge(int from, int to, int id) {
  e[ecnt] = (Edge){head[from], to, id};
  head[from] = ecnt++;
}
int getf(int x) { return x == p[x] ? x : (p[x] = getf(p[x])); }
bool noAns() {
  int t = 0;
  for (int i = 1; i <= n; ++i)
    if (d[i] == -1)
      return false;
    else
      t ^= d[i];
  if (t) return true;
  return false;
}
void dfs(int u, int f) {
  for (int i = head[u], v; i; i = e[i].next)
    if ((v = e[i].to) != f) {
      dfs(v, u);
      sum[u] ^= sum[v];
      ans[e[i].id] = sum[v];
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &d[i]), p[i] = i;
  if (noAns()) {
    printf("-1");
    return 0;
  }
  for (int i = 1; i <= m; ++i) {
    int u, v, fu, fv;
    scanf("%d%d", &u, &v);
    fu = getf(u), fv = getf(v);
    if (fu != fv) {
      p[fu] = fv;
      addedge(u, v, i), addedge(v, u, i);
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i)
    if (d[i] == 1) ++cnt;
  if (cnt & 1) {
    int last = 0;
    for (int i = 1; i <= n; ++i)
      if (d[i] == 1) {
        if (last)
          sum[i] ^= 1, sum[last] ^= 1, last = 0;
        else
          last = i;
      }
    for (int i = 1; i <= n; ++i)
      if (d[i] == -1) {
        sum[i] ^= 1, sum[last] ^= 1;
        break;
      }
  } else {
    int last = 0;
    for (int i = 1; i <= n; ++i)
      if (d[i] == 1) {
        if (last)
          sum[i] ^= 1, sum[last] ^= 1, last = 0;
        else
          last = i;
      }
  }
  dfs(1, 0);
  int tot = 0;
  for (int i = 1; i <= m; ++i)
    if (ans[i]) ++tot;
  printf("%d\n", tot);
  for (int i = 1; i <= m; ++i)
    if (ans[i]) printf("%d\n", i);
  return 0;
}
