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 M = 300010;
std::map<long long, bool> mp;
int n, m;
int d[M], fa[M];
template <typename T>
inline void read(T &x) {
  x = 0;
  char ch = getchar();
  int f = 1;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  x *= f;
}
int head[M], tot = 0;
struct edge {
  int to, next, index;
} e[M << 1];
inline void add(int u, int v, int ind) {
  e[++tot] = (edge){v, head[u], ind};
  head[u] = tot;
  e[++tot] = (edge){u, head[v], ind};
  head[v] = tot;
}
bool vis[M];
int sum = 0, p;
void dfs1(int pos) {
  vis[pos] = 1;
  sum += (d[pos] == 1);
  if (d[pos] == -1) p = pos;
  for (int i = head[pos], v; i; i = e[i].next)
    if (!vis[v = e[i].to]) dfs1(v), fa[v] = pos;
}
std::vector<int> ans;
void dfs2(int pos) {
  for (int i = head[pos], v; i; i = e[i].next)
    if (fa[v = e[i].to] == pos) {
      dfs2(v);
      if (d[v] == 1) d[v] ^= 1, d[pos] ^= 1, ans.push_back(e[i].index);
    }
}
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; i++) read(d[i]);
  for (int i = 1, u, v; i <= m; i++) {
    read(u);
    read(v);
    if (u > v) std::swap(u, v);
    if (mp[1ll * u * n + m]) continue;
    mp[1ll * u * n + m] = 1;
    add(u, v, i);
    add(v, u, i);
  }
  dfs1(1);
  if (sum & 1) {
    if (!p) {
      printf("-1\n");
      return 0;
    }
    d[p] = 1;
  }
  for (int i = 1; i <= n; i++)
    if (d[i] == -1) d[i] = 0;
  dfs2(1);
  std::sort(ans.begin(), ans.end());
  printf("%d\n", (int)ans.size());
  for (std::vector<int>::iterator it = ans.begin(); it != ans.end(); it++)
    printf("%d\n", *it);
  return 0;
}
