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 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;
}
inline int read() {
  int c = getchar(), fg = 1, sum = 0;
  while (c < '0' || c > '9') {
    if (c == '-') fg = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') sum = sum * 10 + c - '0', c = getchar();
  return sum * fg;
}
const int oo = 0x3f3f3f3f;
const int maxn = 300000;
struct edge {
  int adj, nxt, id;
  edge() {}
  edge(int _adj, int _nxt, int _id) : adj(_adj), nxt(_nxt), id(_id) {}
};
edge e[(maxn << 1) + 5];
int st[maxn + 5], cnt;
inline void add(int first, int second, int id, const int type = 1) {
  e[cnt] = edge(second, st[first], id), st[first] = cnt++;
  if (type) add(second, first, id, 0);
}
int N, M;
int f[maxn + 5];
inline int fa(const int &first) {
  return first == f[first] ? first : f[first] = fa(f[first]);
}
set<pair<int, int> > t;
int inv[maxn + 5], e_used[(maxn << 1) + 5], vis[maxn + 5];
inline void dfs(int first, int fa, int status) {
  vis[first] = 1;
  for (int i = st[first]; ~i; i = e[i].nxt) {
    int second = e[i].adj;
    if (second == fa)
      e_used[e[i].id] = status;
    else
      dfs(second, first, status ^ inv[first]);
  }
}
int d[maxn + 5];
int main() {
  memset(st, -1, sizeof st), cnt = 0;
  N = read(), M = read();
  for (int i = (1), i_end_ = (N); i <= i_end_; ++i) d[i] = read(), f[i] = i;
  for (int i = (1), i_end_ = (M); i <= i_end_; ++i) {
    int first = read(), second = read();
    if (fa(first) != fa(second)) {
      f[fa(first)] = fa(second);
      add(first, second, i);
    }
  }
  for (int i = (1), i_end_ = (N); i <= i_end_; ++i) {
    if (!d[i]) continue;
    if (!~d[i]) {
      t.insert(make_pair(fa(i), i));
      continue;
    }
    set<pair<int, int> >::iterator p = t.lower_bound(make_pair(fa(i), 0));
    if (p != t.end() && p->first == fa(i)) {
      inv[p->second] ^= 1, inv[i] ^= 1;
      t.erase(p);
    } else
      t.insert(make_pair(fa(i), i));
  }
  while (!t.empty()) {
    if (~d[t.begin()->second]) {
      puts("-1");
      return 0;
    }
    t.erase(t.begin());
  }
  for (int i = (1), i_end_ = (N); i <= i_end_; ++i)
    if (!vis[i]) dfs(i, 0, 0);
  int ans = 0;
  for (int i = (1), i_end_ = (M); i <= i_end_; ++i) ans += e_used[i];
  printf("%d\n", ans);
  for (int i = (1), i_end_ = (M); i <= i_end_; ++i)
    if (e_used[i]) printf("%d\n", i);
  return 0;
}
