#include <bits/stdc++.h>
using namespace std;
void read(int &val) {
  int x = 0;
  int bz = 1;
  char c;
  for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
    ;
  if (c == '-') {
    bz = -1;
    c = getchar();
  }
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  val = x * bz;
}
const int INF = 0x3f3f3f3f;
const int maxn = 1e6 + 100;
const int mod = 998244353;
int n, m, a[maxn];
int neg, one;
vector<pair<int, int> > g[maxn];
vector<int> ans;
bool vis[maxn];
int dfs(int u, int fa, int id) {
  int deg = 0;
  vis[u] = true;
  for (auto to : g[u]) {
    if (to.first == fa || vis[to.first]) continue;
    deg ^= dfs(to.first, u, to.second);
  }
  if (neg && (one & 1) && a[u] == -1 && deg) {
    a[u] = 0;
    neg = 0;
    deg = 0;
  }
  if (a[u] == -1) {
    a[u] = deg;
  } else
    a[u] ^= deg;
  if (a[u]) {
    ans.push_back(id);
  }
  return a[u];
}
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; i++) {
    read(a[i]);
    if (a[i] == -1) neg = 1;
    if (a[i] == 1) one++;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    read(u);
    read(v);
    g[u].push_back(make_pair(v, i));
    g[v].push_back(make_pair(u, i));
  }
  if (one & 1 && (neg == 0)) {
    puts("-1\n");
    return 0;
  }
  dfs(1, 0, 0);
  printf("%d\n", ans.size());
  for (auto to : ans) printf("%d ", to);
  puts("");
  return 0;
}
