3 2
1 0 1
1 2
2 3
 10 10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
6 7
8 3
6 4
4 2
9 2
5 10
9 8
10 7
5 1
6 2

2
1
2
 0

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct DS {
  int n;
  vector<int> s;
  DS(int n) : n(n), s(n, -1) {}
  int find(int i) { return s[i] < 0 ? i : (s[i] = find(s[i])); }
  int merge(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return 0;
    if (s[a] == s[b]) s[a]--;
    if (s[b] < s[a]) swap(a, b);
    s[b] = a;
    return 1;
  }
};
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> d(n);
  int tot = 0;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    if (d[i] >= 0) tot += d[i];
  }
  for (int i = 0; i < n; i++) {
    if (d[i] < 0) {
      d[i] = tot % 2;
      tot += d[i];
    }
  }
  if (tot % 2) {
    cout << "-1\n";
    return 0;
  }
  vector<vector<pair<int, int>>> g(n);
  DS ds(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    if (ds.merge(u, v)) {
      g[u].push_back({v, i});
      g[v].push_back({u, i});
    }
  }
  vector<int> s;
  vector<pair<int, int>> p(n, {-1, -1});
  queue<int> q;
  q.push(0);
  while (q.size()) {
    int node = q.front();
    q.pop();
    s.push_back(node);
    for (auto adj : g[node]) {
      if (adj.first == p[node].first) continue;
      p[adj.first] = {node, adj.second};
      q.push(adj.first);
    }
  }
  vector<int> ans;
  for (int i = n - 1; i >= 0; i--) {
    int node = s[i];
    if (d[node] % 2) {
      assert(p[node].first >= 0);
      ans.push_back(p[node].second);
      d[p[node].first]++;
    }
  }
  cout << ans.size() << "\n";
  for (int x : ans) {
    cout << x + 1 << "\n";
  }
  return 0;
}
