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;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int>>> g(n);
  vector<int> d(n);
  vector<int> dist(n, LONG_MAX);
  queue<int> q;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    if (d[i] == -1) {
      q.push(i);
      dist[i] = 0;
    }
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].emplace_back(v, i);
    g[v].emplace_back(u, i);
  }
  if (q.empty()) {
    int z = 0;
    for (int u : d) z ^= u;
    if (z != 0) {
      cout << -1;
      return 0;
    }
    vector<int> mark(m, 0);
    vector<pair<int, int>> oof;
    for (int i = 0; i < n; i++) oof.emplace_back(g[i].size(), i);
    sort(oof.begin(), oof.end());
    vector<int> ans;
    vector<int> dg(n);
    for (auto [_d, u] : oof) {
      cerr << "Line " << 43 << ": "
           << "u"
           << " = " << (u) << '\n';
      for (auto &[v, id] : g[u])
        if (!mark[id]) {
          mark[id] = true;
          if (dg[u] != d[u]) dg[u] ^= 1, d[u] ^= 1, ans.push_back(id);
        }
    }
    cout << ans.size() << '\n';
    for (int u : ans) cout << u + 1 << " ";
    return 0;
  }
  vector<int> mark(m, 0);
  vector<int> dg(n, 0);
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (auto &[v, id] : g[u])
      if (dist[v] > dist[u] + 1) {
        dist[v] = dist[u] + 1;
        q.push(v);
      }
  }
  vector<pair<int, int>> rel;
  for (int i = 0; i < n; i++) rel.emplace_back(dist[i], i);
  sort(rel.rbegin(), rel.rend());
  vector<int> ans;
  for (auto [_d, u] : rel) {
    for (auto &[v, id] : g[u])
      if (mark[id] == 0) {
        mark[id] = 1;
        if (dg[u] != d[u]) dg[u] ^= 1, dg[v] ^= 1, ans.push_back(id);
      }
  }
  cout << ans.size() << '\n';
  for (int u : ans) cout << u + 1 << '\n';
  return 0;
}
