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;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
const int N = 3e5 + 10, M = 6e5 + 10;
int head[N], ver[M], nxt[M], tot = 1;
void add(int x, int y) {
  ver[++tot] = y;
  nxt[tot] = head[x];
  head[x] = tot;
}
int d[N], zzt = 0, c = 0, fa[N];
bool vis[N];
void dfs1(int x) {
  vis[x] = 1;
  if (d[x] == -1) zzt = x;
  c += (d[x] == 1);
  for (int i = head[x]; i; i = nxt[i]) {
    int y = ver[i];
    if (vis[y]) continue;
    fa[y] = x;
    dfs1(y);
  }
}
vector<int> ans;
void dfs2(int x) {
  for (int i = head[x]; i; i = nxt[i]) {
    int y = ver[i];
    if (fa[y] != x) continue;
    dfs2(y);
    if (d[y]) {
      d[x] ^= 1;
      ans.push_back(i >> 1);
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
  map<pair<int, int>, bool> vis;
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    if (vis[make_pair(min(u, v), max(u, v))]) continue;
    vis[make_pair(min(u, v), max(u, v))] = 1;
    add(u, v);
    add(v, u);
  }
  dfs1(1);
  if (c % 2 && !zzt) return printf("-1"), 0;
  if (c % 2 && zzt) d[zzt] = 1;
  for (int i = 1; i <= n; i++)
    if (d[i] == -1) d[i] = 0;
  dfs2(1);
  sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());
  printf("%d\n", (int)ans.size());
  for (int i = 0; (unsigned)i < ans.size(); i++) printf("%d\n", ans[i]);
  return 0;
}
