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 <class T>
inline void amin(T &x, const T &y) {
  if (y < x) x = y;
}
template <class T>
inline void amax(T &x, const T &y) {
  if (x < y) x = y;
}
template <class Iter>
void rprintf(const char *fmt, Iter begin, Iter end) {
  for (bool sp = 0; begin != end; ++begin) {
    if (sp)
      putchar(' ');
    else
      sp = true;
    printf(fmt, *begin);
  }
  putchar('\n');
}
const int MAXN = 300111;
int N, M;
int D[MAXN];
vector<pair<int, int> > G[MAXN];
vector<pair<int, int> > H[MAXN];
int par[MAXN];
int act[MAXN];
void MAIN() {
  scanf("%d%d", &N, &M);
  for (int i = 0, i_len = (N); i < i_len; ++i) scanf("%d", D + i);
  for (int i = 0, i_len = (M); i < i_len; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    G[x].emplace_back(y, i);
    G[y].emplace_back(x, i);
  }
  int cnt = count(D, D + N, 1);
  if (cnt % 2 == 1 && count(D, D + N, -1) == 0) {
    puts("-1");
    return;
  }
  if (cnt % 2 == 1) {
    *find(D, D + N, -1) = 1;
  }
  vector<int> ord;
  ord.reserve(N);
  memset(par, -1, sizeof par);
  ord.push_back(0);
  par[0] = 0;
  for (int i_ = 0, i__len = (N); i_ < i__len; ++i_) {
    int v = ord[i_];
    for (__typeof((G[v]).begin()) e = (G[v]).begin(), e_end = (G[v]).end();
         e != e_end; ++e)
      if (par[e->first] == -1) {
        par[e->first] = v;
        H[v].push_back(*e);
        ord.push_back(e->first);
      }
  }
  vector<int> ans;
  for (int i_ = 0, i__len = (N); i_ < i__len; ++i_) {
    int v = ord[N - 1 - i_];
    if (D[v] == 1) act[v] = 1;
    for (__typeof((H[v]).begin()) e = (H[v]).begin(), e_end = (H[v]).end();
         e != e_end; ++e) {
      if (act[e->first]) {
        ans.push_back(e->second);
        act[v]++;
      }
    }
    act[v] &= 1;
  }
  printf("%d\n", (int)ans.size());
  for (__typeof((ans).begin()) e = (ans).begin(), e_end = (ans).end();
       e != e_end; ++e)
    printf("%d\n", *e + 1);
}
int main() {
  int TC = 1;
  for (int tc = 0, tc_len = (TC); tc < tc_len; ++tc) MAIN();
  return 0;
}
