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>
#pragma optimize GCC(3)
#pragma optimize GCC(2)
using namespace std;
int n, m;
int col[300005];
struct node {
  int to, next;
} bian[300005 * 2];
int cnt = 1;
int head[300005];
int used[300005];
int fa[300005], id[300005];
vector<int> s[300005];
int num[300005];
int finish[300005];
int prepare[300005];
int top = 0;
int ans = 0;
int dui[300005];
int front, rear;
int vs[300005], from[300005];
int t = 0;
inline int find(int x) {
  if (fa[x] != x) fa[x] = find(fa[x]);
  return fa[x];
}
inline void uni(int x, int y) {
  int xf = find(x), yf = find(y);
  if (xf == yf) return;
  fa[yf] = xf;
}
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 void bfs(int s) {
  if (finish[s]) return;
  register int i;
  int u, v;
  front = 1, rear = 2;
  dui[1] = s;
  vs[s] = ++t;
  int f = 0;
  while (front != rear) {
    u = dui[front];
    for (i = head[u]; i; i = bian[i].next) {
      v = bian[i].to;
      if (vs[v] == t) continue;
      vs[v] = t, dui[rear++] = v, from[v] = i;
      if (col[v] == 1 && finish[v] != 1) {
        f = 1;
        break;
      }
    }
    if (f) break;
    front++;
  }
  finish[s] = finish[v] = 1;
  int p = v;
  for (i = from[v]; p != s; i = from[p]) {
    p = bian[i ^ 1].to;
    used[i / 2] ^= 1;
  }
}
int main() {
  n = read(), m = read();
  register int i, j;
  for (i = 1; i <= n; i++) col[i] = read(), fa[i] = i;
  int x, y;
  for (i = 1; i <= m; i++) {
    x = read(), y = read();
    ADD(x, y);
    uni(x, y);
  }
  for (i = 1; i <= n; i++) {
    if (col[i] == 1 || col[i] == -1) {
      x = find(i);
      if (!id[x]) id[x] = ++top;
      if (col[i] == 1)
        num[id[x]]++, s[id[x]].push_back(i);
      else
        prepare[id[x]] = i;
    }
  }
  if (top == 0) {
    printf("0\n");
    return 0;
  }
  for (i = 1; i <= top; i++) {
    if (num[i] % 2 == 0) continue;
    if (prepare[i]) {
      col[prepare[i]] = 1;
      continue;
    }
    printf("-1\n");
    return 0;
  }
  return 0;
  for (i = 1; i <= top; i++) {
    for (j = s[i].size() - 1; j >= 0; j--) {
      bfs(s[i][j]);
    }
  }
  for (i = 1; i <= m; i++) {
    if (used[i]) ans++;
  }
  printf("%d\n", ans);
  for (i = 1; i <= m; i++) {
    if (used[i]) printf("%d\n", i);
  }
  return 0;
}
