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;
const int MAXN = 303333;
int dsu[MAXN], n, m, d[MAXN], vis[MAXN], deg[MAXN];
vector<pair<int, int> > G[MAXN];
int find(int x) { return x == dsu[x] ? x : dsu[x] = find(dsu[x]); }
bool merge(int x, int y) {
  x = find(x), y = find(y);
  if (x != y) {
    dsu[x] = y;
    return true;
  }
  return false;
}
pair<int, int> edges[MAXN];
void dfs(int v, int fa) {
  for (auto [u, id] : G[v])
    if (u != fa) {
      dfs(u, v);
      if (d[u] != deg[u]) {
        vis[id] ^= 1;
        d[u] ^= 1;
        d[v] ^= 1;
      }
    }
}
int main() {
  scanf("%d%d", &n, &m);
  int odd = 0, idx = -1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &d[i]);
    odd += d[i] == 1;
    dsu[i] = i;
  }
  for (int i = 1; i <= m; ++i) {
    static int u, v;
    scanf("%d%d", &u, &v);
    edges[i] = {u, v};
    if ((d[u] == -1 && d[v] != -1) || (d[u] != -1 && d[v] == -1)) idx = i;
    if (merge(u, v)) {
      G[u].emplace_back(v, i);
      G[v].emplace_back(u, i);
    }
  }
  if ((odd & 1) && idx == -1) {
    puts("-1");
    return 0;
  } else {
    if (odd & 1) {
      vis[idx] = 1;
      deg[edges[idx].first] = deg[edges[idx].second] = 1;
    }
    for (int i = 1; i <= n; ++i)
      if (d[i] == -1) d[i] = deg[i] = 0;
    dfs(1, -1);
    vector<int> ans;
    for (int i = 1; i <= m; ++i)
      if (vis[i]) ans.push_back(i);
    int r = (int)ans.size();
    printf("%d\n", r);
    for (int i = 0; i < r; ++i) printf("%d%c", ans[i], " \n"[i == r - 1]);
  }
  return 0;
}
