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>
const int N = 300007, inf = 0x3f3f3f3f;
using namespace std;
int col[N], out[N];
set<int> edges[N];
struct ar {
  int u, v, id;
  ar() {}
  ar(int a, int b, int c) {
    u = a;
    v = b;
    id = c;
  }
};
ar arestas[N];
int nos[N], fase[N];
set<int> vis;
int tot;
int pontos[N];
int cmp(int u, int v) {
  return edges[u].size() - pontos[u] < edges[v].size() - pontos[v];
}
int other(int u, int i) {
  return u == arestas[i].u ? arestas[i].v : arestas[i].u;
}
int dfs(int u) {
  int v;
  if (vis.find(u) != vis.end()) return 0;
  vis.insert(u);
  for (int x : edges[u]) {
    v = other(u, x);
    if (vis.find(v) == vis.end() and
        (fase[v] != col[v] or col[v] == -1 or dfs(v))) {
      if (fase[v] != col[v]) fase[v] = !fase[v];
      edges[u].erase(x);
      edges[v].erase(x);
      out[x] = 1;
      tot--;
      return 1;
    }
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  int n, m, u, v;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> col[i];
    nos[i] = i;
  }
  tot = m;
  for (int i = 0; i < m; ++i) {
    cin >> u >> v;
    arestas[i] = ar(u, v, i);
    edges[u].insert(i);
    edges[v].insert(i);
    fase[u] = !fase[u];
    fase[v] = !fase[v];
    if (col[v] == -1) pontos[u]--;
    if (col[u] == -1) pontos[v]--;
  }
  sort(nos + 1, nos + n + 1, cmp);
  for (int i = 1; i <= n; ++i) {
    u = nos[i];
    if (col[u] != -1 and col[u] != fase[u]) {
      vis.clear();
      if (dfs(u) == 0) {
        cout << -1 << endl;
        return 0;
      } else {
        fase[u] = !fase[u];
      }
    }
  }
  cout << tot << endl;
  for (int i = 0; i < m; ++i) {
    if (out[i] == 0) cout << i + 1 << endl;
  }
}
