#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ds(n);
  int min1at = -1;
  int count1 = 0;
  for (int i = 0; i < n; i++) {
    cin >> ds[i];
    if (ds[i] == -1) {
      min1at = i;
    }
    if (ds[i] == 1) {
      count1++;
    }
  }
  vector<vector<pair<int, int>>> graph(n, vector<pair<int, int>>());
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    graph[u].push_back(make_pair(v, i + 1));
    graph[v].push_back(make_pair(u, i + 1));
  }
  int start = 0;
  if (min1at != -1) {
    start = min1at;
  } else if (count1 % 2 == 1) {
    cout << -1;
    return 0;
  }
  vector<bool> visited(n, false);
  visited[start] = true;
  vector<pair<int, int>> parentedge(n);
  queue<int> q;
  stack<int> s;
  q.push(start);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    s.push(v);
    for (pair<int, int> u : graph[v]) {
      if (!visited[u.first]) {
        visited[u.first] = true;
        q.push(u.first);
        parentedge[u.first] = make_pair(v, u.second);
      }
    }
  }
  vector<int> selected;
  vector<int> edgecount(n, 0);
  while (!s.empty()) {
    int v = s.top();
    s.pop();
    if (ds[v] != -1) {
      if (ds[v] != edgecount[v] % 2) {
        selected.push_back(parentedge[v].second);
        edgecount[parentedge[v].first]++;
      }
    }
  }
  cout << selected.size() << "\n";
  for (int i = 0; i < selected.size(); i++) {
    cout << selected[i] << " ";
  }
  return 0;
}
