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;
const int N = 3e5 + 10, lg = 23;
int n, m, d[N], par[N], psum[N], p[N], bad_par[N], high[N], bad[N], dp[N][lg];
bool mark[N];
vector<int> adj[N];
vector<pair<int, int> > edge;
void make_par(int v, int p, int h) {
  mark[v] = 1;
  par[v] = dp[v][0] = p;
  high[v] = h;
  for (int i : adj[v])
    if (!mark[i]) make_par(i, v, h + 1);
}
int go_up(int v, int dis) {
  int u = 0;
  while (dis) {
    if (dis & 1) v = dp[v][u];
    u++;
    dis /= 2;
  }
  return v;
}
int LCA(int v, int u) {
  if (high[v] > high[u]) swap(v, u);
  u = go_up(u, high[u] - high[v]);
  if (v == u) return v;
  for (int i = lg - 1; i >= 0; i--)
    if (dp[v][i] != dp[u][i]) {
      v = dp[v][i];
      u = dp[u][i];
    }
  return par[v];
}
void solve(int v, int u) {
  int w = LCA(v, u);
  p[w] -= 2;
  p[v]++;
  p[u]++;
}
int dfs(int v) {
  vector<int> tmp;
  for (int i : adj[v])
    if (i != par[v] && par[i] == v) {
      int k = dfs(i);
      if (k != -1) tmp.push_back(k);
    }
  if (tmp.size() % 2) {
    for (int i = 0; i + 1 < tmp.size(); i += 2) solve(tmp[i], tmp[i + 1]);
    if (bad[v]) {
      solve(tmp.back(), v);
      return -1;
    } else
      return tmp.back();
  } else {
    for (int i = 0; i < tmp.size(); i += 2) solve(tmp[i], tmp[i + 1]);
    if (bad[v])
      return v;
    else
      return -1;
  }
}
void make_psum(int v) {
  psum[v] = p[v];
  for (int i : adj[v])
    if (i != par[v] && par[i] == v) {
      make_psum(i);
      psum[v] += psum[i];
    }
}
void make_ans(int v) {
  for (int i : adj[v])
    if (i != par[v] && par[i] == v) make_ans(i);
  if (v && psum[v] > 0) bad_par[v] = 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> d[i];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
    edge.push_back({a, b});
  }
  int tmp = 0;
  for (int i = 0; i < n; i++)
    if (d[i] == 0 || d[i] == 1) {
      bad[i] = (adj[i].size() % 2) != d[i];
      if (bad[i]) tmp++;
    }
  if (tmp % 2) {
    for (int i = 0; i < n; i++)
      if (d[i] == -1) {
        bad[i] = 1;
        tmp++;
        break;
      }
  }
  if (tmp & 1) return cout << -1, 0;
  make_par(0, 0, 0);
  for (int j = 1; j < lg; j++)
    for (int i = 0; i < n; i++) dp[i][j] = dp[dp[i][j - 1]][j - 1];
  dfs(0);
  make_psum(0);
  make_ans(0);
  int ans = 0;
  for (int i = 0; i < n; i++)
    if (bad_par[i]) ans++;
  cout << m - ans << '\n';
  for (int i = 0; i < edge.size(); i++) {
    pair<int, int> p = edge[i];
    int v = p.first, u = p.second, w = LCA(v, u);
    if (high[v] > high[u]) swap(v, u);
    if (w == v && par[u] != v)
      cout << i + 1 << '\n';
    else if (!bad_par[u])
      cout << i + 1 << '\n';
  }
}
