#include <bits/stdc++.h>
using namespace std;
int n, m;
int d[300005];
vector<pair<int, int>> e[300005];
int a[300005];
set<int> s;
int dfs(int t) {
  if (a[t]) return 0;
  a[t] = 1;
  int x = 0;
  for (auto i : e[t])
    if (!a[i.first]) {
      int y = dfs(i.first);
      if (y) s.insert(i.second);
      x ^= y;
    }
  if (d[t] == -1) return 0;
  return x ^ d[t];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> d[i], a[i] = 0;
  for (int j = 0; j < m; j++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    e[x].push_back({y, j});
    e[y].push_back({x, j});
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == -1) res |= dfs(i);
  }
  res |= dfs(0);
  if (res)
    cout << -1;
  else {
    cout << s.size() << '\n';
    for (int i : s) cout << i + 1 << ' ';
  }
  return 0;
}
