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;
int read() {
  char ch;
  for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-';) ch = getchar();
  int d = 0, t = 1;
  if (ch == '-') {
    t = -1;
    ch = getchar();
  }
  for (; ch >= '0' && ch <= '9'; ch = getchar()) d = d * 10 + ch - 48;
  return d * t;
}
int n, m, sum, x, y, t, kkk, vv, ans, cnt;
struct sdt {
  int to, nxt, val;
} a[600005];
int head[300005], d[300005], w[300005];
bool vis[300005];
bool f;
void add(int fr, int tox, int index) {
  a[++cnt].to = tox;
  a[cnt].nxt = head[fr];
  a[cnt].val = index;
  head[fr] = cnt;
}
void dfs(int p, int v) {
  w[v] = d[p] == 1;
  vis[p] = 1;
  for (int i = head[p]; i; i = a[i].nxt) {
    kkk = a[i].to;
    vv = a[i].val;
    if (vis[kkk]) continue;
    dfs(kkk, vv);
    w[v] ^= w[vv];
  }
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) {
    d[i] = read();
    if (d[i] == -1) {
      f = 1;
      t = i;
    } else
      sum += d[i];
  }
  if (sum % 2 == 1 && f == 0) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    x = read();
    y = read();
    add(x, y, i);
    add(y, x, i);
  }
  if (!f)
    dfs(1, 0);
  else
    dfs(t, 0);
  for (int i = 1; i <= m; i++)
    if (w[i]) ans++;
  printf("%d\n", ans);
  for (int i = 1; i <= m; i++)
    if (w[i]) printf("%d\n", i);
  return 0;
}
