#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
const LL mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int r = 0;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    if (d[i] == -1) r = i;
  }
  vector<vector<int>> lj(n);
  map<pair<int, int>, int> a;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    lj[u].push_back(v);
    lj[v].push_back(u);
    a[{u, v}] = i;
    a[{v, u}] = i;
  }
  vector<int> us(n);
  vector<int> ans;
  function<int(int, int)> dfs = [&](int k, int pre) {
    us[k] = 1;
    int tmp = 0;
    for (auto i : lj[k]) {
      if (i == pre || us[i]) continue;
      tmp += dfs(i, k);
    }
    tmp %= 2;
    if (tmp) {
      if (d[k])
        return 0;
      else {
        ans.push_back(a[{pre, k}]);
        return 1;
      }
    } else {
      if (d[k] == 1) {
        ans.push_back(a[{pre, k}]);
        return 1;
      } else
        return 0;
    }
  };
  if (dfs(r, r))
    cout << "-1\n";
  else {
    sort(ans.begin(), ans.end());
    cout << ans.size() << '\n';
    for (auto i : ans) cout << i + 1 << '\n';
  }
}
