#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
int n, m, vis[N], d[N];
vector<pair<int, int> > g[N], g1[N];
int sub = 0, fa[N], up[N], cur[N];
vector<int> id;
void dfs(int u) {
  vis[u] = 1;
  id.push_back(u);
  if (~d[u]) sub ^= d[u];
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i].first;
    if (vis[v]) continue;
    fa[v] = u;
    up[v] = g[u][i].second;
    g1[u].push_back(g[u][i]);
    dfs(v);
  }
}
vector<int> vec;
void work(int u) {
  for (int i = 0; i < g1[u].size(); ++i) {
    int v = g1[u][i].first;
    work(v);
  }
  if (cur[u] != d[u]) {
    assert(fa[u]);
    cur[fa[u]] ^= 1;
    cur[u] ^= 1;
    vec.push_back(up[u]);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &d[i]);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(make_pair(v, i));
    g[v].push_back(make_pair(u, i));
  }
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      id.clear();
      sub = 0;
      dfs(i);
      for (int j = 0; j < id.size(); ++j)
        if (d[id[j]] == -1) {
          if (sub == 0)
            d[id[j]] = 0;
          else {
            d[id[j]] = 1;
            sub ^= 1;
          }
        }
      if (sub) {
        cout << -1 << '\n';
        return 0;
      }
      work(i);
    }
  sort(vec.begin(), vec.end());
  cout << vec.size() << '\n';
  for (int i = 0; i < vec.size(); ++i) cout << vec[i] << '\n';
  return 0;
}
