#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, m, s[300002], viz[300002];
vector<int> ans;
vector<pair<int, int> > v[300002];
void dfs(int dad, int nod, int nr) {
  viz[nod] = 1;
  for (int i = 0; i < v[nod].size(); ++i) {
    int vecin = v[nod][i].first;
    if (viz[vecin]) continue;
    dfs(nod, vecin, v[nod][i].second);
  }
  if (s[nod] == 1) {
    ans.push_back(nr);
    s[dad] ^= 1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  int sm = 0;
  bool neg = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
    if (s[i] == -1)
      neg = 1;
    else
      sm += s[i];
  }
  if (sm % 2 == 1 && !neg) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; ++i)
    if (s[i] == -1) {
      if (sm % 2 == 1)
        s[i] = 1, sm = 0;
      else
        s[i] = 0;
    }
  for (int i = 1; i <= m; ++i) {
    int a, b;
    cin >> a >> b;
    v[a].push_back({b, i});
    v[b].push_back({a, i});
  }
  dfs(0, 1, 0);
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); ++i) cout << ans[i] << " ";
  return 0;
}
