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;
const int MAX = 3e5 + 1;
int n, m, d[MAX], comp[MAX], back[MAX], vert[MAX * 2];
bool neg, one;
vector<int> adj[MAX], ans;
int get_comp(int u) {
  if (comp[u] != u) {
    comp[u] = get_comp(comp[u]);
  }
  return comp[u];
}
void solve(int u) {
  if (d[u] == -1) {
    d[u] = one;
    one = false;
  }
  for (int edge : adj[u]) {
    if (edge != back[u]) {
      back[vert[edge]] = edge ^ 1;
      solve(vert[edge]);
    }
  }
  if (d[u]) {
    ans.push_back(1 + back[u] / 2);
  }
  d[vert[back[u]]] ^= d[u];
}
int main() {
  scanf("%d %d", &n, &m);
  for (int u = 1; u <= n; u++) {
    scanf("%d", &d[u]);
    neg |= d[u] == -1;
    one ^= d[u] == 1;
    comp[u] = u;
  }
  if (!neg && one) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < m; i++) {
    int a = i * 2, b = a + 1, ca, cb;
    scanf("%d %d", &vert[a], &vert[b]);
    ca = get_comp(vert[a]);
    cb = get_comp(vert[b]);
    if (ca != cb) {
      comp[ca] = cb;
      adj[vert[a]].push_back(b);
      adj[vert[b]].push_back(a);
    }
  }
  back[1] = -1;
  solve(1);
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) {
    if (i) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
}
