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>
long long read() {
  long long x = 0, f = 1;
  char c;
  do {
    c = getchar();
    if (c == '-') f = -1;
  } while (c < '0' || c > '9');
  do {
    x = x * 10 + c - '0';
    c = getchar();
  } while (c >= '0' && c <= '9');
  return f * x;
}
long long min(long long a, long long b) { return a < b ? a : b; }
long long max(long long a, long long b) { return a > b ? a : b; }
bool umin(long long &a, long long b) {
  if (b < a) return a = b, 1;
  return 0;
}
bool umax(long long &a, long long b) {
  if (b > a) return a = b, 1;
  return 0;
}
struct edge {
  long long v, dex, nxt;
} e[300011 << 1 | 1];
long long cnt = 0, last[300011];
void adde(long long u, long long v, long long dex) {
  e[++cnt].v = v, e[cnt].dex = dex;
  e[cnt].nxt = last[u], last[u] = cnt;
}
long long fa[300011], root[300011], d[300011], tot[300011], change[300011];
void build(long long u, long long rt) {
  tot[u] = (d[u] == 1);
  root[u] = rt;
  if (d[u] == -1) change[rt] = u;
  for (long long i = last[u]; i; i = e[i].nxt) {
    long long v = e[i].v;
    if (root[v]) continue;
    fa[v] = u;
    build(v, rt);
    tot[u] += tot[v];
  }
}
long long f[300011];
std::vector<long long> ans[300011];
void dfs(long long u) {
  for (long long i = last[u]; i; i = e[i].nxt) {
    long long v = e[i].v;
    if (fa[v] != u) continue;
    dfs(v);
    if (f[v] == 1) {
      ans[root[u]].push_back(e[i].dex), f[u] ^= 1;
    }
  }
}
int main() {
  long long n = read(), m = read();
  for (long long i = 1; i <= n; ++i) f[i] = d[i] = read();
  bool flag = 0;
  for (long long i = 1; i <= m; ++i) {
    long long u = read(), v = read();
    adde(u, v, i), adde(v, u, i);
  }
  for (long long i = 1; i <= n; ++i)
    if (!fa[i]) {
      build(i, i);
      if (tot[i] & 1) {
        if (!change[i])
          flag = 1;
        else
          f[change[i]] = 1;
      }
      dfs(i);
    }
  if (flag)
    puts("-1");
  else {
    long long all = 0;
    for (long long i = 1; i <= n; ++i) all += ans[i].size();
    printf("%lld\n", all);
    for (long long i = 1; i <= n; ++i)
      for (auto x : ans[i]) printf("%lld\n", x);
  }
  return 0;
}
