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 D[1000000];
vector<pair<int, int> > G[1000000];
int CURD[1000000];
bool SEL[1000000];
bool VIS[1000000];
void go(int v, int p, int idx) {
  VIS[v] = true;
  for (auto pa : G[v]) {
    int u = pa.first;
    if (!VIS[u]) {
      go(u, v, pa.second);
    }
  }
  if (D[v] != -1) {
    if (CURD[v] != D[v]) {
      SEL[idx] = true;
      CURD[v] = (CURD[v] + 1) % 2;
      CURD[p] = (CURD[p] + 1) % 2;
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int root = 1;
  bool has = false;
  int odd = 0;
  for (int i = (0); i < (n); i++) {
    int d;
    scanf("%d", &d);
    D[i + 1] = d;
    CURD[i + 1] = 0;
    VIS[i + 1] = false;
    if (d == -1) {
      root = i + 1;
      has = true;
    } else if (d == 1)
      ++odd;
  }
  for (int i = (0); i < (m); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[a].push_back(make_pair(b, i + 1));
    G[b].push_back(make_pair(a, i + 1));
    SEL[i + 1] = false;
  }
  if (odd % 2 == 1 && !has) {
    printf("-1\n");
    return 0;
  }
  go(root, -1, -1);
  int cnt = 0;
  for (int i = (1); i <= (m); i++) cnt += SEL[i];
  printf("%d\n", cnt);
  for (int i = (1); i <= (m); i++) {
    if (SEL[i]) printf("%d\n", i);
  }
}
