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;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= 1000000007;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
  }
  return res;
}
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
vector<pair<int, int> > g[500000];
int d[500000], fa[500000], ff[500000];
int num[500000];
int fckn, ans;
void dfs(int u, int f = 0) {
  int tmp = 0;
  for (auto x : g[u]) {
    int v = x.first;
    if (v == f) continue;
    fa[v] = x.second;
    dfs(v, u);
    tmp += ff[v];
  }
  if (f && tmp % 2 == 0) {
    if (d[u] == 1)
      ff[u] = 1, num[fa[u]] = 1, ans++;
    else {
      ff[u] = 0;
      num[fa[u]] = 0;
    }
  } else if (f && (tmp & 1)) {
    if (d[u] == 0)
      ff[u] = 1, num[fa[u]] = 1, ans++;
    else {
      ff[u] = 0;
      num[fa[u]] = 0;
    }
  } else {
    if (tmp % 2 == 0 && d[u] == 1) {
      fckn = 1;
    } else if ((tmp & 1) && d[u] == 0) {
      fckn = 1;
    } else
      fckn = 0;
  }
}
int par[500000];
int find(int u) { return par[u] == u ? par[u] : par[u] = find(par[u]); }
int main() {
  int n = read(), m = read();
  int s = 0;
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    d[i] = read();
    if (d[i] == -1) s = i;
  }
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read();
    if (find(u) != find(v)) {
      g[u].push_back(make_pair(v, i));
      g[v].push_back(make_pair(u, i));
      par[find(u)] = find(v);
    }
  }
  if (s == 0) s = 1;
  dfs(s);
  if (fckn) {
    puts("-1");
  } else {
    printf("%d\n", ans);
    for (int i = 1; i <= m; i++)
      if (num[i]) {
        printf("%d\n", i);
      }
  }
  return 0;
}
