#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 550;
int n, m, d[maxn];
vector<pair<int, int>> G[maxn];
vector<int> ans;
int deg[maxn], vis[maxn];
int dfs(int u) {
  vis[u] = 1;
  int res = (d[u] == 1);
  for (auto it : G[u]) {
    int v = it.first;
    int eid = it.second;
    if (vis[v]) continue;
    int tmp = dfs(v);
    if (tmp & 1) ans.push_back(eid);
    res += tmp;
  }
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", d + i);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back({v, i});
    G[v].push_back({u, i});
  }
  int all = 0;
  for (int i = 1; i <= n; i++) all += (d[i] == 1);
  for (int i = 1; i <= n; i++) {
    if (d[i] == -1) {
      if (all & 1)
        d[i] = 1, all++;
      else
        d[i] = 0;
    }
  }
  if (all & 1)
    puts("-1");
  else {
    dfs(1);
    cout << ans.size() << endl;
    sort(ans.begin(), ans.end());
    for (auto x : ans) printf("%d ", x);
  }
}
