#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 5;
long long n, m;
long long a[N];
vector<pair<long, long> > graph[N];
vector<long long> ans;
bool mark[N + 1];
bool dfs(long long u) {
  mark[u] = true;
  bool parity = false;
  for (auto nei : graph[u]) {
    long long v = nei.first;
    if (!mark[v]) {
      if (dfs(v)) {
        ans.push_back(nei.second);
        parity = !parity;
      }
    }
  }
  return ((a[u] == 1) ^ parity);
}
int main() {
  cin >> n >> m;
  long long root = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == -1) {
      root = i;
    }
  }
  for (int e = 1; e <= m; e++) {
    long long u, v;
    cin >> u >> v;
    graph[u].push_back({v, e});
    graph[v].push_back({u, e});
  }
  if (!dfs(root) || a[root] == -1) {
    cout << ans.size() << endl;
    for (long long nei : ans) {
      cout << nei << endl;
    }
  } else {
    cout << -1 << endl;
  }
}
