#include <bits/stdc++.h>
#pragma optimize GCC(3)
#pragma optimize GCC(2)
using namespace std;
int n, m;
int col[300005];
int a[300005];
struct node {
  int to, next;
} bian[300005 * 2];
int cnt = 1;
int head[300005];
int vs[300005];
int used[300005];
int tot = 0;
int s = 0;
int ans = 0;
inline int read() {
  int ans = 0;
  int f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) ans = ans * 10 + ch - '0';
  return ans * f;
}
inline void add(int u, int v) {
  cnt++;
  bian[cnt].to = v;
  bian[cnt].next = head[u];
  head[u] = cnt;
}
inline void ADD(int u, int v) {
  add(u, v);
  add(v, u);
}
inline bool dfs(int u, int f) {
  register int i;
  int v;
  vs[u] = 1;
  for (i = head[u]; i; i = bian[i].next) {
    v = bian[i].to;
    if (vs[v]) continue;
    if (dfs(v, u)) used[i / 2] = 1;
  }
  if (a[u] != col[u] && col[u] != -1) {
    a[f] ^= 1, ans++, a[u] ^= 1;
    return 1;
  }
  return 0;
}
int main() {
  n = read(), m = read();
  register int i, j;
  for (i = 1; i <= n; i++) {
    col[i] = read();
    if (col[i] == 1) tot ^= 1;
    if (col[i] == -1) s = i;
  }
  int x, y;
  for (i = 1; i <= m; i++) {
    x = read(), y = read();
    ADD(x, y);
  }
  if (tot && !s) {
    printf("-1\n");
    return 0;
  }
  if (!s) s = 1;
  dfs(s, 0);
  printf("%d\n", ans);
  for (i = 1; i <= m; i++)
    if (used[i]) printf("%d\n", i);
  return 0;
}
