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, val[300010], used[300010], par[300010], pr[300010][21], h[300010],
    dp[300010];
vector<pair<int, int> > adj[300010];
vector<int> mn, on;
int find_root(int x) {
  if (par[x] == x) return x;
  return par[x] = find_root(par[x]);
}
void dfs(int x, int p) {
  pr[x][0] = p;
  for (int i = 1; i < 20; i++) pr[x][i] = pr[pr[x][i - 1]][i - 1];
  for (pair<int, int> v : adj[x]) {
    if (v.first == p) continue;
    h[v.first] = h[x] + 1;
    dfs(v.first, x);
  }
}
int lca(int x, int y) {
  if (h[x] < h[y]) swap(x, y);
  for (int i = 19; i >= 0; i--)
    if (h[pr[x][i]] >= h[y]) x = pr[x][i];
  if (x == y) return x;
  for (int i = 19; i >= 0; i--)
    if (pr[x][i] != pr[y][i]) x = pr[x][i], y = pr[y][i];
  return pr[x][0];
}
void dfs2(int x, int p, int ed) {
  for (pair<int, int> v : adj[x]) {
    if (v.first == p) continue;
    dfs2(v.first, x, v.second);
    dp[x] += dp[v.first];
  }
  if (ed > -1) {
    used[ed] = dp[x] % 2;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  int a, b;
  int c0 = 0, c1 = 0, cm = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", val + i);
    if (val[i] == 0) c0++;
    if (val[i] == 1) c1++, on.push_back(i);
    if (val[i] == -1) cm++, mn.push_back(i);
    par[i] = i;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    int pa = find_root(a), push_back = find_root(b);
    if (pa == push_back) continue;
    par[pa] = push_back;
    adj[a].push_back({b, i});
    adj[b].push_back({a, i});
  }
  if ((c1 & 1) && !cm) {
    printf("-1");
    return 0;
  }
  dfs(1, 1);
  if (c1 % 2 == 1) on.push_back(mn.back());
  for (int i = 0; i < (int)(on).size(); i += 2) {
    int v = on[i], u = on[i + 1];
    int lc = lca(u, v);
    dp[v]++, dp[u]++, dp[lc] -= 2;
  }
  dfs2(1, 1, -1);
  int res = 0;
  for (int i = 0; i < m; i++) {
    if (used[i]) res++;
  }
  cout << res << endl;
  for (int i = 0; i < m; i++) {
    if (used[i]) printf("%d\n", i + 1);
  }
  return 0;
}
