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;
template <typename T>
inline void read(T &x) {
  char c;
  bool nega = 0;
  while ((!isdigit(c = getchar())) && (c != '-'))
    ;
  if (c == '-') {
    nega = 1;
    c = getchar();
  }
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (nega) x = -x;
}
template <typename T>
inline void writep(T x) {
  if (x > 9) writep(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  writep(x);
}
template <typename T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
const long long MAX = 300005;
long long n, m;
long long a[MAX];
basic_string<long long> g[MAX];
pair<long long, long long> b[MAX];
long long mark[MAX];
long long res[MAX];
long long cnt = 0;
stringstream ss;
void dfs(long long x) {
  mark[x] = 1;
  for (int id = 0; id < g[x].size(); id++) {
    long long y = ((b[id].second == x) ? b[id].first : b[id].second);
    if (mark[y]) continue;
    res[y] = id;
    dfs(y);
    a[x] ^= a[y];
  }
  if (a[x]) {
    cnt++;
    ss << res[x] << '\n';
  }
}
int main() {
  read(n);
  read(m);
  long long tmp = -1;
  long long ind = 0;
  for (int i = 0; i < n; i++) {
    read(a[i]);
    if (a[i] == -1)
      tmp = i;
    else
      ind ^= a[i];
  }
  if (ind == 1 && tmp == -1) {
    write(-1);
    return 0;
  }
  if (ind == 1) a[tmp] = 1;
  for (int i = 0; i < n; i++)
    if (a[i] == -1) a[i] = 0;
  for (int i = 1; i <= m; i++) {
    long long u, v;
    read(u);
    read(v);
    u--;
    v--;
    b[i] = make_pair(u, v);
    g[u] += i;
    g[v] += i;
  }
  dfs(0);
  writeln(cnt);
  cout << ss.string();
}
