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>
#pragma GCC optimize("Ofast")
using namespace std;
const long long MAX = 3e5 + 20;
long long inf = (long long)1e18;
long long mod = (long long)1e9 + 7;
long long n, m, k, used[MAX], type[MAX], par[MAX], cnt[MAX];
vector<long long> gr[MAX];
set<pair<long long, long long>> edges;
long long cnt1, pos;
map<pair<long long, long long>, long long> inds;
void dfs(long long v) {
  used[v] = 1;
  if (type[v] == -1)
    pos = 1;
  else if (type[v] == 1)
    cnt1++;
  for (auto u : gr[v]) {
    if (!used[u]) dfs(u);
  }
}
void repaint(long long v, long long p) {
  used[v] = 2;
  if (type[v] == -1 && cnt1 % 2) {
    type[v] = 1;
    cnt1++;
  } else if (type[v] == -1)
    type[v] = 0;
  for (auto u : gr[v]) {
    if (used[u] != 2) repaint(u, v);
  }
}
void del_edges(long long v, long long p) {
  used[v] = 3;
  if (type[v] == 1) cnt[v]++;
  for (auto u : gr[v]) {
    if (u == p) continue;
    if (used[u] != 3) {
      del_edges(u, v);
      cnt[v] += cnt[u];
    } else {
      edges.erase({v, u});
      edges.erase({u, v});
    }
  }
  if (cnt[v] % 2 == 0) {
    edges.erase({v, p});
    edges.erase({p, v});
  }
}
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> type[i];
  for (int i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    gr[a].push_back(b);
    gr[b].push_back(a);
    inds[{a, b}] = i + 1;
    edges.insert({a, b});
  }
  long long ok = 1;
  for (int i = 1; i <= n; i++) {
    pos = 0;
    cnt1 = 0;
    if (!used[i]) {
      dfs(i);
      if (pos == 0 && cnt1 % 2)
        ok = 0;
      else {
        repaint(i, 0);
        del_edges(i, 0);
      }
    }
  }
  if (ok == 0)
    cout << -1;
  else {
    cout << edges.size() << "\n";
    for (auto u : edges) {
      cout << inds[u] << "\n";
    }
  }
}
int main() {
  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  ios::sync_with_stdio(0);
  long long q;
  q = 1;
  while (q--) {
    solve();
  }
  return 0;
}
