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 read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; c < 48 || c > 57; c = getchar())
    if (c == '-') f = -1;
  for (; c > 47 && c < 58; c = getchar()) x = (x << 1) + (x << 3) + c - 48;
  return x * f;
}
int n, m, d[300050], x, fl;
int st[300050], pv[600050], p1[600050], pe[600050], tot;
inline void side(int u, int v, int id) {
  pv[++tot] = v;
  pe[tot] = id;
  p1[tot] = st[u];
  st[u] = tot;
}
inline void init() {
  n = read();
  m = read();
  int s = 0;
  for (int i = 1; i <= n; ++i) {
    d[i] = read();
    if (d[i] == -1)
      x = i;
    else
      s += d[i];
  }
  if (!x && (s & 1)) {
    fl = 1;
    return;
  }
  for (int i = 1; i <= m; ++i) {
    int u = read(), v = read();
    side(u, v, i);
    side(v, u, i);
  }
}
int vis[300050], use[300050];
void dfs(int x, int e) {
  vis[x] = 1;
  use[e] = d[x];
  for (int i = st[x]; i; i = p1[i]) {
    int v = pv[i], e2 = pe[i];
    if (vis[v]) continue;
    dfs(v, e2);
    use[e] ^= use[e2];
  }
}
inline void solve() {
  if (fl) {
    puts("-1");
    return;
  }
  if (x)
    dfs(x, 0);
  else
    dfs(1, 0);
  int k = 0;
  for (int i = 1; i <= m; ++i)
    if (use[i]) ++k;
  printf("%d\n", k);
  for (int i = 1; i <= m; ++i)
    if (use[i]) printf("%d\n", i);
}
int main() {
  init();
  solve();
  return 0;
}
