#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
vector<int> e[300001];
map<ii, int> ecount;
vector<int> d;
vector<bool> visited;
vector<int> ans;
void dfs(int i) {
  visited[i] = true;
  for (auto& e : e[i]) {
    if (visited[e]) continue;
    dfs(e);
    if (d[e] == 1) {
      ans.push_back(ecount[make_pair(i, e)]);
      d[i] = (d[i] + 1) % 2;
    }
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  d.resize(n + 1);
  visited.resize(n + 1);
  int dsum = 0;
  vector<int> minus;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    if (d[i] == -1)
      minus.push_back(i);
    else
      dsum += d[i];
  }
  if (dsum % 2 == 1) {
    if (minus.empty()) {
      printf("-1");
      return 0;
    }
    d[minus[0]] = 1;
    for (int i = 1; i < minus.size(); i++) d[minus[i]] = 0;
  } else {
    for (int i = 0; i < minus.size(); i++) d[minus[i]] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    e[a].push_back(b);
    e[b].push_back(a);
    ecount[make_pair(a, b)] = ecount[make_pair(b, a)] = i + 1;
  }
  dfs(1);
  printf("%d\n", ans.size());
  for (auto& a : ans) printf("%d\n", a);
  return 0;
}
