#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
struct edge {
  int nxt, ed;
} e[2 * N];
int head[N], num, vis[N], used[N], d[N];
pair<int, int> fa[N];
void add(int x, int y) {
  e[num].ed = y;
  e[num].nxt = head[x];
  head[x] = num++;
}
void dfs(int u) {
  vis[u] = 1;
  for (int i = head[u]; ~i; i = e[i].nxt) {
    int v = e[i].ed;
    if (vis[v]) continue;
    fa[v] = make_pair(i / 2, u);
    dfs(v);
    if (d[v] == 1) {
      d[u] ^= 1;
      used[i / 2] = 1;
      d[v] = 0;
    }
  }
}
int main() {
  int n, m, u = -1, x, y;
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    if (d[i] == -1) u = i;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    add(x, y), add(y, x);
  }
  dfs(1);
  if (d[1] == 1) {
    if (u == -1) return 0 * printf("-1\n");
    while (u != 1) {
      used[fa[u].first] ^= 1;
      u = fa[u].second;
    }
  }
  int cnt = 0;
  for (int i = 0; i < m; i++)
    if (used[i]) cnt++;
  printf("%d\n", cnt);
  for (int i = 0; i < m; i++)
    if (used[i]) printf("%d\n", i + 1);
  return 0;
}
