#include <bits/stdc++.h>
using namespace std;
int n, m;
int d[333333];
vector<pair<int, int> > mp[333333];
vector<int> qu;
bool v[333333];
int rudu[333333];
bool dfs(int p, int ok) {
  v[p] = 1;
  for (auto t : mp[p]) {
    if (v[t.first]) continue;
    rudu[p] ^= dfs(t.first, t.second);
  }
  if (rudu[p] ^ d[p]) {
    qu.push_back(ok);
    return true;
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  int yu = -1, xrq = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    if (d[i] == -1)
      if (~yu)
        d[i] = 0;
      else
        yu = i;
    else
      xrq ^= d[i];
  }
  if (yu == -1 && xrq) {
    puts("-1");
    return 0;
  }
  int a1, a2;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a1, &a2);
    mp[a1].emplace_back(a2, i);
    mp[a2].emplace_back(a1, i);
  }
  if (~yu) d[yu] = xrq;
  dfs(1, 0);
  printf("%lu\n", qu.size());
  sort(qu.begin(), qu.end());
  for (auto t : qu) printf("%d\n", t);
  return 0;
}
