#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int N, M;
int lab[300100];
vector<pair<int, int> > g[300100];
set<int> s;
bool visited[300100];
bool dfs(int v, int e) {
  visited[v] = 1;
  bool mask = lab[v];
  for (auto p : g[v]) {
    int w = p.first, f = p.second;
    if (visited[w]) continue;
    mask ^= dfs(w, f);
  }
  if (mask) s.insert(e);
  return mask;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M;
  int ncnt = 0;
  int cnt = 0;
  for (int i = 1; i <= N; i++) {
    cin >> lab[i];
    if (lab[i] == -1) ncnt++;
    if (lab[i] == 1) cnt++;
  }
  for (int i = 1; i <= N && ncnt > 0; i++) {
    if (lab[i] == -1) {
      ncnt--;
      if (ncnt == 0) {
        lab[i] = (cnt % 2);
        if (lab[i]) cnt++;
      } else {
        lab[i] = 0;
      }
    }
  }
  if (cnt % 2) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 1; i <= M; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  dfs(1, -1);
  cout << s.size() << '\n';
  for (int e : s) {
    cout << e << '\n';
  }
  return 0;
}
