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;
int uf[310100];
int get_fa(int x) { return uf[x] == x ? x : uf[x] = get_fa(uf[x]); }
struct Edge {
  Edge *next;
  int np;
  int id;
} E[310100 * 2], *V[310100];
int tope = -1;
void add_edge(int x, int y, int id) {
  E[++tope].np = y;
  E[tope].id = id;
  E[tope].next = V[x];
  V[x] = &E[tope];
}
int qq[310100];
int pnt[310100];
int pid[310100];
void dfs(int now) {
  for (Edge *ne = V[now]; ne; ne = ne->next) {
    if (ne->np == pnt[now]) continue;
    pnt[ne->np] = now;
    pid[ne->np] = ne->id;
    dfs(ne->np);
  }
}
int times[310100];
void dfs2(int now) {
  for (Edge *ne = V[now]; ne; ne = ne->next) {
    if (ne->np == pnt[now]) continue;
    dfs2(ne->np);
    times[now] = (times[now] + times[ne->np]) % 2;
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", qq + i);
  for (int i = 0; i < n; i++) uf[i] = i;
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    if (get_fa(x) != get_fa(y)) {
      uf[get_fa(x)] = get_fa(y);
      add_edge(x, y, i + 1);
      add_edge(y, x, i + 1);
    }
  }
  dfs(0);
  vector<int> A, B;
  for (int i = 0; i < n; i++) {
    int x;
    x = qq[i];
    if (x == 1) A.push_back(i);
    if (x == -1) B.push_back(i);
  }
  if (A.size() % 2 == 1) {
    if (B.size() == 0) {
      printf("-1\n");
      return 0;
    } else {
      A.push_back(B.back());
      B.pop_back();
    }
  }
  for (int i = 0; i < A.size(); i++) times[A[i]]++;
  dfs2(0);
  int ans = 0;
  for (int i = 1; i < n; i++)
    if (times[i] == 1) ans++;
  printf("%d\n", ans);
  for (int i = 1; i < n; i++)
    if (times[i]) printf("%d\n", pid[i]);
}
