#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const long long mod = 1e9 + 7;
const long long M = 1e8 + 5;
const long long N = 6e5 + 5;
long long n, m;
struct node {
  long long ver, next;
} e[N];
long long tot, head[N];
long long d[N], v[N];
long long ans[N], t;
inline void add(long long x, long long y) {
  e[++tot].ver = y;
  e[tot].next = head[x];
  head[x] = tot;
}
inline void addedge(long long x, long long y) {
  add(x, y);
  add(y, x);
}
bool dfs(long long x) {
  v[x] = 1;
  long long res = d[x];
  for (register long long i = head[x]; i; i = e[i].next) {
    long long y = e[i].ver;
    if (v[y]) continue;
    if (dfs(y)) ans[++t] = (i + 1) / 2, res ^= 1;
  }
  if (d[x] == -1) res = 0;
  return res;
}
inline void solve() {
  cin >> n >> m;
  long long op = -1, res = 0;
  for (register long long i = 1; i <= n; i++) {
    scanf("%lld", &d[i]);
    if (d[i] == -1)
      op = i;
    else
      res ^= d[i];
  }
  for (register long long i = 1; i <= m; i++) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    addedge(x, y);
  }
  if (op == -1 && res) {
    puts("-1");
    return;
  }
  if (op == -1) op = 1;
  dfs(op);
  cout << t << endl;
  sort(ans + 1, ans + t + 1);
  for (register long long i = 1; i <= t; i++) printf("%lld\n", ans[i]);
}
signed main() {
  long long T = 1;
  for (long long index = 1; index <= T; index++) {
    solve();
  }
  return 0;
}
