#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 300300;
int N, M;
int d[N_MAX];
map<pair<int, int>, int> edge_ids;
vector<int> edges[N_MAX];
vector<pair<int, int>> answer;
bool seen[N_MAX];
int dfs(int x, int p) {
  seen[x] = true;
  int parity = (d[x] == -1 ? 0 : d[x]);
  for (int y : edges[x]) {
    if (y == p) continue;
    if (seen[y]) continue;
    if (dfs(y, x) == 1) {
      answer.push_back(pair<int, int>(min(x, y), max(x, y)));
      parity++;
    }
  }
  return parity % 2;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> M;
  int free_idx = -1;
  int num_ones = 0;
  for (int i = 0; i < N; i++) {
    cin >> d[i];
    if (d[i] == -1)
      free_idx = i;
    else if (d[i] == 1)
      num_ones++;
    seen[i] = false;
  }
  if (free_idx == -1) {
    if (num_ones % 2 == 1) {
      cout << "-1\n";
      return 0;
    }
    free_idx = 0;
  }
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    pair<int, int> e(min(u, v), max(u, v));
    if (edge_ids.find(e) != edge_ids.end()) continue;
    edge_ids[e] = i + 1;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  dfs(free_idx, -1);
  cout << answer.size() << "\n";
  for (const auto &e : answer) {
    cout << edge_ids[e] << "\n";
  }
  return 0;
}
