#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
int d[N], vis[N], v[N], n, m, cnt, rt = 1;
struct _ {
  int to, id;
};
vector<_> g[N];
void dfs(int x) {
  if (vis[x]) return;
  vis[x] = 1;
  for (_ e : g[x]) {
    dfs(e.to);
    if (d[e.to] == 1) v[e.id] ^= 1, d[e.to] ^= 1, d[x] ^= 1;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", d + i), rt = ~d[i] ? rt : i;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back((_){v, i}), g[v].push_back((_){u, i});
  }
  dfs(rt);
  if (d[rt] == 1) return puts("-1"), 0;
  for (int i = 1; i <= m; ++i)
    if (v[i]) ++cnt;
  printf("%d\n", cnt);
  for (int i = 1; i <= m; ++i)
    if (v[i]) printf("%d\n", i);
}
