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;
const int N = 301010;
inline char get(void) {
  static char buf[100000], *S = buf, *T = buf;
  if (S == T) {
    T = (S = buf) + fread(buf, 1, 100000, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
inline void read(int &x) {
  static char c;
  x = 0;
  int sgn = 0;
  for (c = get(); c < '0' || c > '9'; c = get())
    if (c == '-') sgn = 1;
  for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
  if (sgn) x = -x;
}
struct edge {
  int to, next, id;
  edge(int t = 0, int n = 0, int i = 0) : to(t), next(n), id(i) {}
};
edge G[N << 1];
int head[N], d[N], vis[N];
int cnt, Gcnt, n, m, x, y, rt, res;
int ans[N];
inline void AddEdge(int from, int to, int id) {
  G[++Gcnt] = edge(to, head[from], id);
  head[from] = Gcnt;
  G[++Gcnt] = edge(from, head[to], id);
  head[to] = Gcnt;
}
bool dfs(int u) {
  int to, f, du = 0;
  vis[u] = 1;
  for (int i = head[u]; i; i = G[i].next) {
    to = G[i].to;
    if (vis[to]) continue;
    f = dfs(to);
    du ^= f;
    if (f) ans[++cnt] = G[i].id;
  }
  if (du == d[u] || d[u] == -1) return false;
  return true;
}
int main(void) {
  read(n);
  read(m);
  rt = 0;
  for (int i = 1; i <= n; i++) read(d[i]);
  for (int i = 1; i <= n; i++) {
    if (d[i] == -1) rt = i;
  }
  for (int i = 1; i <= m; i++) {
    read(x);
    read(y);
    AddEdge(x, y, i);
  }
  if (!rt) rt = 1;
  if (dfs(rt)) {
    puts("-1");
  } else {
    printf("%d\n", cnt);
    for (int i = 1; i <= cnt; i++) printf("%d\n", ans[i]);
  }
  return 0;
}
