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;
int n, m, d[((int)301 * 1000)], ans;
pair<int, int> b[((int)301 * 1000)];
vector<pair<int, int> > e[((int)301 * 1000)];
bool mark[((int)301 * 1000)], ed_in[((int)301 * 1000)];
void dfs(int x, int par = 0, int e_id = 0) {
  mark[x] = 1;
  bool deg = 0;
  for (auto u : e[x]) {
    if (mark[u.first] || u.first == par) continue;
    dfs(u.first, x, u.second);
    if (ed_in[u.second] == 1) deg = !deg;
  }
  if (d[x] == -1 || deg == d[x]) return;
  if (par == 0) {
    cout << "-1\n";
    exit(0);
  }
  ed_in[e_id] = 1;
  ans++;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> d[i], b[i] = {d[i], i};
  for (int i = 1; i <= m; i++) {
    int v, u;
    cin >> v >> u;
    e[v].push_back({u, i});
    e[u].push_back({v, i});
  }
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; i++)
    if (!mark[i]) dfs(i);
  cout << ans << "\n";
  for (int i = 1; i <= m; i++)
    if (ed_in[i]) cout << i << " ";
  cout << "\n";
  return 0;
}
