#include <bits/stdc++.h>
using namespace std;
bool dfs(int cur, int edge, vector<vector<pair<int, int> > > &g,
         set<int> &edges, vector<int> &p, vector<bool> &visited) {
  visited[cur] = true;
  int cur_p = p[cur];
  for (int i = 0; i < g[cur].size(); i++) {
    int next = g[cur][i].first, next_p = g[cur][i].second;
    if (!visited[next]) {
      cur_p = cur_p ^ dfs(next, next_p, g, edges, p, visited);
    }
  }
  if (cur_p == 1) {
    edges.insert(edge);
  }
  return cur_p;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int n_cnt = 0, p_cnt = 0;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    n_cnt += p[i] < 0 ? 1 : 0;
    p_cnt += p[i] > 0 ? 1 : 0;
  }
  if (n_cnt == 0 && p_cnt % 2 == 1) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (p_cnt % 2 == 1 && p[i] == -1) {
      p[i] = 1;
      n_cnt--;
      p_cnt++;
    } else if (p[i] == -1) {
      p[i] = 0;
      n_cnt--;
    }
  }
  vector<vector<pair<int, int> > > g(n, vector<pair<int, int> >());
  int from, to;
  for (int i = 1; i <= m; i++) {
    cin >> from >> to;
    from--, to--;
    g[from].push_back(make_pair(to, i));
    g[to].push_back(make_pair(from, i));
  }
  set<int> edges;
  vector<bool> visited(n, false);
  dfs(0, -1, g, edges, p, visited);
  cout << edges.size() << "\n";
  for (set<int>::iterator it = edges.begin(); it != edges.end(); it++) {
    cout << *it << " ";
  }
  cout << "\n";
  return 0;
}
