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 = 3e5 + 1e3 + 7;
struct node {
  int ne, to, tag, id, fr;
} edg[N * 2 + 1], e[N * 2 + 1];
int head[N], cnt, n, m, ans[N], fa[N], d[N], fae[N], anss[N];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void build(int u, int v, int i) {
  ++cnt;
  edg[cnt].ne = head[u];
  edg[cnt].to = v;
  edg[cnt].tag = 0;
  edg[cnt].id = i;
  head[u] = cnt;
}
void kruskal() {
  for (int i = 1; i <= m; i++) {
    int u = e[i].fr, v = e[i].to;
    int fu = find(u), fv = find(v);
    if (fu != fv) {
      fa[fu] = fv;
      build(u, v, i);
      build(v, u, i);
    }
  }
}
int kk, rt;
void dfs(int i, int f) {
  for (int tmp = head[i]; tmp; tmp = edg[tmp].ne) {
    int v = edg[tmp].to;
    if (i == rt) kk = edg[tmp].id;
    if (v == f) continue;
    fae[v] = edg[tmp].id;
    if (d[v] == 1) {
      ans[kk]++;
      for (int zz = head[v]; zz; zz = edg[zz].ne) {
        if (edg[zz].to != i) ans[edg[zz].id]--;
      }
    }
    dfs(v, i);
  }
}
void calc(int i, int f) {
  for (int tmp = head[i]; tmp; tmp = edg[tmp].ne) {
    int v = edg[tmp].to;
    if (v == f) continue;
    anss[fae[v]] = anss[fae[i]] + ans[fae[v]];
    calc(v, i);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]), fa[i] = i;
  for (int i = 1; i <= m; i++) scanf("%d%d", &e[i].fr, &e[i].to);
  kruskal();
  int tmp = 0;
  for (int i = 1; i <= n; i++)
    if (d[i] == 1) tmp++;
  if (tmp & 1) {
    for (int i = 1; i <= n; i++)
      if (d[i] == -1) {
        tmp++;
        rt = d[i];
        break;
      }
    if (tmp & 1) {
      printf("-1");
      return 0;
    }
  }
  if (!rt) rt = 1;
  dfs(rt, 0);
  calc(rt, 0);
  for (int i = 1; i <= m; i++) {
    if (anss[i] & 1) anss[0]++;
  }
  printf("%d\n", anss[0]);
  for (int i = 1; i <= m; i++)
    if (anss[i] & 1) printf("%d\n", i);
}
