#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int cp[300000];
int find(int x) { return cp[x] = cp[x] == x ? x : find(cp[x]); }
void union_(int x, int y) { cp[find(x)] = find(y); }
vector<vector<int> > g;
vector<int> A;
vector<int> D;
vector<int> ans;
map<pair<int, int>, int> mp;
void dfs(int u, int p = -1) {
  for (int v : g[u])
    if (v != p) dfs(v, u);
  if (!u) return;
  if (A[u] % 2 == D[u] % 2) return;
  ans.push_back(mp[{min(u, p), max(u, p)}]);
  D[p]++;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  g.assign(n, vector<int>());
  A.resize(n);
  D.assign(n, 0);
  int cnt = 0;
  int neg = 0;
  for (int i = 0; i < n; ++i) {
    cp[i] = i;
    cin >> A[i];
    if (A[i] + 1)
      cnt += A[i];
    else
      neg++;
    cnt %= 2;
  }
  if (cnt && !neg) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (cnt && A[i] == -1) {
      cnt = 0;
      A[i] = 1;
    } else if (A[i] == -1)
      A[i] = 0;
  }
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    mp[{min(u, v), max(u, v)}] = i + 1;
    if (find(u) != find(v)) {
      union_(u, v);
      g[u].push_back(v);
      g[v].push_back(u);
    }
  }
  dfs(0, -1);
  cout << ans.size() << "\n";
  for (int a : ans) cout << a << "\n";
}
