#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline void chmin(A &a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
  if (a < b) a = b;
}
long long N, M;
long long D[333333];
bool vis[333333];
long long pre[333333];
vector<long long> G[333333];
long long w[333333];
map<pair<long long, long long>, long long> id;
signed main() {
  scanf("%lld%lld", &N, &M);
  for (long long i = 0; i < (N); i++) scanf("%lld", &D[i]);
  for (long long i = 0; i < (M); i++) {
    long long a, b;
    scanf("%lld%lld", &a, &b);
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
    id[{a, b}] = id[{b, a}] = i;
  }
  long long x = -1, y = -1;
  long long cnt = 0;
  for (long long i = 0; i < (N); i++) {
    if (D[i] == -1) x = i;
    if (D[i] == 1) y = i, cnt++;
  }
  if (x == -1 && cnt % 2) {
    cout << -1 << endl;
    return 0;
  }
  if (x == -1) x = y;
  if (x == -1) {
    cout << 0 << endl;
    return 0;
  }
  vector<long long> vs = {x};
  vis[x] = true;
  for (long long i = 0; i < (N); i++) {
    long long v = vs[i];
    for (auto u : G[v]) {
      if (vis[u]) continue;
      vis[u] = true;
      pre[u] = v;
      vs.push_back(u);
    }
  }
  vector<long long> ans;
  for (long long i = N - 1; i > 0; i--) {
    long long v = vs[i];
    if (D[v] == 1) w[v]++;
    if (w[v] & 1) {
      ans.push_back(id[{pre[v], v}]);
    }
    w[pre[v]] += w[v];
  }
  sort((ans).begin(), (ans).end());
  printf("%lld\n", (long long)ans.size());
  for (long long i = 0; i < (ans.size()); i++) printf("%lld\n", ans[i] + 1);
  return 0;
}
