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 maxn = 3 * 1e6 + 5;
int d[maxn];
struct Node {
  int b, v, n;
} t[maxn];
int h[maxn], vis[maxn];
int cur[maxn], x[maxn], y[maxn], ans[maxn];
int flag = 0;
int cnt = 0;
int num = 0;
void dfs(int u, int pan) {
  vis[u] = 1;
  for (int i = h[u]; i; i = t[i].n) {
    int v = t[i].b;
    if (vis[v]) continue;
    dfs(v, t[i].v);
  }
  if (d[u] != -1 && cur[u] != d[u]) {
    if (!pan) {
      flag = 0;
      return;
    }
    if (x[pan] == u) swap(x[pan], y[pan]);
    cur[x[pan]] ^= 1;
    ans[++num] = pan;
  }
}
void add(int a, int b, int v) { t[++cnt] = (Node){b, v, h[a]}, h[a] = cnt; }
int main() {
  memset(vis, 0, sizeof(vis));
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    x[i] = a;
    y[i] = b;
    add(a, b, i);
    add(b, a, i);
  }
  flag = 1;
  int p = 1;
  for (int i = 1; i <= n; i++)
    if (d[i] == -1) p = i;
  dfs(p, 0);
  if (flag) {
    printf("%d\n", num);
    sort(ans + 1, ans + 1 + num);
    for (int i = 1; i <= num; i++) printf("%d\n", ans[i]);
  } else
    printf("-1\n");
  return 0;
}
