#include <bits/stdc++.h>
using namespace std;
struct edge {
  int v, from;
} e[300005 * 2];
int first[300005], d[300005], n, m, ans = 0, tot = 0;
bool vis[300005], a[300005 * 2];
int addedge(int u, int v) {
  tot++;
  e[tot].v = v;
  e[tot].from = first[u];
  first[u] = tot;
  tot++;
  e[tot].v = u;
  e[tot].from = first[v];
  first[v] = tot;
}
int dfs(int x) {
  vis[x] = true;
  for (int i = first[x]; i; i = e[i].from) {
    int v = e[i].v;
    if (!vis[v]) {
      if (dfs(v) & 1) {
        a[i] = true;
        ans++;
        if (d[x] != 2) {
          d[x] = 1 - d[x];
        }
      }
    }
  }
  return d[x];
}
int main() {
  scanf("%d %d", &n, &m);
  int flag = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    if (d[i] == -1) {
      flag = i;
      d[i] = 2;
    }
  }
  int u, v;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &u, &v);
    addedge(u, v);
  }
  if (flag) {
    dfs(flag);
  } else {
    if (dfs(1) & 1) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= tot; i += 2) {
    if (a[i] || a[i + 1]) {
      printf("%d ", i / 2 + 1);
    }
  }
  return 0;
}
