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 d[300010], ans[300010], head[300010], nxt[600010], to[600010], id[600010],
    num, ansnum, n, m, x, y, pos;
bool vis[300010], ok;
void add(int x, int y, int idx) {
  nxt[++num] = head[x];
  to[head[x] = num] = y;
  id[num] = idx;
}
void dfs(int p) {
  vis[p] = 1;
  for (int i = head[p]; i; i = nxt[i])
    if (!vis[to[i]]) {
      dfs(to[i]);
      if (d[to[i]] == 1) {
        ans[++ansnum] = id[i];
        if (d[p] != -1) d[p] ^= 1;
      }
    }
}
int main() {
  scanf("%d%d", &n, &m);
  pos = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    if (d[i] == -1) {
      ok = 1;
      pos = i;
    }
    if (d[i] == 1) num++;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    add(x, y, i);
    add(y, x, i);
  }
  if (!ok && num % 2) {
    printf("-1\n");
    return 0;
  }
  if (ok) {
    if (num % 2) d[pos] = 1;
    for (int i = 1; i < pos; i++) d[i] = 0;
  }
  dfs(1);
  printf("%d\n", ansnum);
  for (int i = 1; i <= ansnum; i++) printf("%d\n", ans[i]);
  return 0;
}
