#include <bits/stdc++.h>
using namespace std;
long long int n, m, d[300005], mark[300005];
vector<pair<long long int, long long int> > g[300005];
vector<long long int> ans;
long long int dfs(long long int st, long long int pr) {
  mark[st] = 1;
  long long int ct = 0;
  for (pair<long long int, long long int> v : g[st])
    if (v.first != pr && !mark[v.first]) {
      long long int val = dfs(v.first, st);
      if (val == 1) {
        ct++;
        ans.push_back(v.second);
      }
    }
  if (d[st] == -1) return 0;
  if (d[st] == ct % 2) return 0;
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (long long int i = 1; i <= n; ++i) cin >> d[i];
  for (long long int i = 1; i <= m; ++i) {
    long long int u, v;
    cin >> u >> v;
    g[u].push_back(make_pair(v, i));
    g[v].push_back(make_pair(u, i));
  }
  for (long long int i = 1; i <= n; ++i)
    if (d[i] == -1) {
      dfs(i, i);
      cout << ans.size() << '\n';
      sort(ans.begin(), ans.end());
      for (long long int v : ans) cout << v << '\n';
      return 0;
    }
  long long int ret = dfs(1, 1);
  if (ret == 1)
    cout << -1 << '\n';
  else {
    cout << ans.size() << '\n';
    sort(ans.begin(), ans.end());
    for (long long int v : ans) cout << v << '\n';
  }
}
