#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
vector<pair<long long, long long> > g[N];
set<long long> ans;
long long vis[N], d[N], root = 1;
int n, m;
long long i, j, k, u, v;
long long dfs(long long u) {
  if (vis[u]++) return 1;
  long long deg = 0, k, v;
  for (auto x : g[u]) {
    v = x.first;
    k = dfs(v);
    if (k == 0) {
      ans.insert(x.second);
      deg++;
    }
  }
  return d[u] == -1 || deg % 2 == d[u];
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> d[i];
    if (d[i] == -1) root = i;
  }
  for (int i = 1; i <= m; ++i) {
    cin >> u >> v;
    g[u].push_back(make_pair(v, i));
    g[v].push_back(make_pair(u, i));
  }
  k = dfs(root);
  if (k == 0) {
    return !printf("-1\n");
  }
  cout << ans.size() << "\n";
  for (auto p : ans) {
    cout << p << " ";
  }
  return 0;
}
