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>
void dbg(const char* xn, T x) {
  if (0) cout << xn << ": " << x << "\n";
}
template <class T, class... TA>
void dbg(const char* xn, T x, TA... t) {
  while (*xn != ',')
    if (0) cout << *xn++;
  if (0) cout << ": " << x << ",";
  dbg(xn + 1, t...);
}
template <class T>
inline bool upd_max(T& x, T y) {
  return y > x ? x = y, true : false;
}
template <class T>
inline bool upd_min(T& x, T y) {
  return y < x ? x = y, true : false;
}
const int N = 600007;
long long n, m, hasToBe[N], deg[N], badNei[N], removed[N], doubled[N];
vector<long long> g[N];
bitset<N> bad;
map<pair<long long, long long>, long long> edge;
map<pair<long long, long long>, long long> already;
void removeEdges() {
  for (long long v = 1; v <= n; ++v) {
    for (auto u : g[v]) badNei[v] += bad[u];
    if ((badNei[v] & 1) != bad[v]) {
      long long kept = -1;
      for (auto u : g[v])
        if (bad[u]) {
          kept = u;
          break;
        }
      if (kept == -1) continue;
      for (auto u : g[v]) {
        if (!bad[u] || kept == u) continue;
        removed[edge[make_pair(v, u)]] = 1;
        bad[u] = 0;
      }
    } else {
      for (auto u : g[v]) {
        if (!bad[u]) continue;
        removed[edge[make_pair(v, u)]] = 1;
        bad[u] = 0;
      }
      bad[v] = 0;
    }
  }
  for (long long v = 1; v <= n; ++v) {
    for (auto u : g[v]) {
      if (bad[v] == bad[u])
        removed[edge[make_pair(v, u)]] = 1, bad[v] = 0, bad[u] = 0;
    }
  }
  for (long long v = 1; v <= n; ++v) {
    if (hasToBe[v] != -1) continue;
    for (auto u : g[v]) {
      if (!bad[u]) continue;
      removed[edge[make_pair(v, u)]] = 1;
      bad[u] = 0;
    }
  }
}
void solve() {
  cin >> n >> m;
  for (long long i = 1; i <= (n); ++i) cin >> hasToBe[i];
  for (long long i = 1; i <= (m); ++i) {
    long long a, b;
    cin >> a >> b;
    deg[a] ^= 1;
    deg[b] ^= 1;
    if (already[make_pair(a, b)]) {
      doubled[i] = 1;
      continue;
    }
    already[make_pair(a, b)] = 1;
    g[a].push_back(b);
    g[b].push_back(a);
    edge[make_pair(a, b)] = edge[make_pair(b, a)] = i;
  }
  for (long long i = 1; i <= (n); ++i)
    if ((~hasToBe[i]) && deg[i] != hasToBe[i]) bad[i] = 1;
  long long isBad = 0;
  for (long long i = 1; i <= (n); ++i) isBad |= bad[i];
  if (isBad) removeEdges();
  for (long long i = 1; i <= (n); ++i)
    if (bad[i]) cout << "-1", exit(0);
  long long Sz = 0;
  for (long long i = 1; i <= (m); ++i)
    if (!removed[i] || doubled[i]) ++Sz;
  cout << Sz << '\n';
  for (long long i = 1; i <= (m); ++i)
    if (!removed[i] || doubled[i]) cout << i << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}
