#include <bits/stdc++.h>
using namespace std;
const int MX = 3e5 + 5;
struct Edge {
  int v, nxt;
} E[MX * 2];
pair<int, int> edge[MX];
int a[MX], IN[MX], head[MX], tot;
void add(int u, int v) {
  E[tot].v = v;
  E[tot].nxt = head[u];
  head[u] = tot++;
}
int vis[MX];
vector<int> ver;
void dfs(int u, int fa) {
  int j = -1;
  vis[u] = 1;
  for (int i = head[u]; ~i; i = E[i].nxt) {
    int v = E[i].v;
    if (v == fa) {
      j = i;
      continue;
    }
    if (vis[v]) continue;
    dfs(v, u);
  }
  if ((a[u] == 1 && IN[u] % 2 == 0) && fa > 0) {
    ver.push_back(j);
    IN[fa]++;
  }
  if ((a[u] == 0 && IN[u] % 2 == 1) && fa > 0) {
    ver.push_back(j);
    IN[fa]++;
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  memset(head, -1, sizeof(head));
  int rt = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == -1) rt = i;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &edge[i].first, &edge[i].second);
    add(edge[i].first, edge[i].second);
    add(edge[i].second, edge[i].first);
  }
  dfs(rt, 0);
  if (a[rt] == -1 || a[rt] == (IN[rt] % 2)) {
    sort(ver.begin(), ver.end());
    printf("%d\n", ver.size());
    for (int i = 0; i < ver.size(); i++)
      printf("%d%c", ver[i] / 2 + 1, i == ver.size() - 1 ? '\n' : ' ');
  } else
    printf("-1\n");
  return 0;
}
