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 void R(int &v) {
  static char ch;
  v = 0;
  bool p = 0;
  do {
    ch = getchar();
    if (ch == '-') p = 1;
  } while (!isdigit(ch));
  while (isdigit(ch)) {
    v = (v + (v << 2) << 1) + (ch ^ '0');
    ch = getchar();
  }
  if (p) v = -v;
}
struct node {
  int to, id;
  node(int to, int id) : to(to), id(id) {}
  node() {}
};
std::vector<node> q[300005];
int n, m;
int d[300005];
bool vis[300005];
inline void create(int x, int y, int id) {
  q[x].push_back(node(y, id));
  q[y].push_back(node(x, id));
}
bool used[300005];
int fa[300005], fap[300005];
inline void dfs(int x, int pre) {
  vis[x] = 1;
  if (x != 1) {
    if (d[x] == 1) {
      d[x] = 0;
      used[pre] ^= 1;
      if (d[fa[x]] != -1) d[fa[x]] ^= 1;
    }
  }
  node *p;
  for (int i = 0; i < q[x].size(); ++i) {
    p = &q[x][i];
    if (!vis[p->to]) {
      fa[p->to] = x;
      fap[p->to] = p->id;
      dfs(p->to, p->id);
    }
  }
}
int pos;
int main() {
  R(n), R(m);
  for (int i = 1; i <= n; ++i) {
    R(d[i]);
    if (d[i] == -1) pos = i;
  }
  int x, y;
  for (int i = 1; i <= m; ++i) {
    R(x), R(y);
    create(x, y, i);
  }
  dfs(1, 0);
  if (d[1] == 1 && (!pos)) {
    puts("-1");
    return 0;
  }
  int t = pos;
  if (d[1] == 1) {
    while (t != 1) {
      used[fap[t]] ^= 1;
      t = fa[t];
    }
  }
  int cnt = 0;
  for (int i = 1; i <= m; ++i) {
    cnt += used[i];
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= m; ++i) {
    if (used[i]) printf("%d\n", i);
  }
  return 0;
}
