#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int const N = 300 * 1000 + 16;
int const M = 1000 * 1000 * 1000 + 7;
int n, m;
int d[N];
int vis[N];
vector<int> ans;
vector<pair<int, int>> g[N];
void dfs(int u) {
  vis[u] = 1;
  for (auto const& e : g[u]) {
    int v, idx;
    tie(v, idx) = e;
    if (not vis[v]) {
      dfs(v);
      if (d[v]) {
        ans.emplace_back(idx);
        d[v] ^= 1;
        d[u] ^= 1;
      }
    }
  }
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cin >> n >> m;
  int cnt[8] = {};
  auto p = cnt + 3;
  for (int i = 1; i <= n; ++i) {
    cin >> d[i];
    p[d[i]]++;
  }
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].emplace_back(v, i);
    g[v].emplace_back(u, i);
  }
  if ((p[1] & 1)) {
    if (not p[-1]) return cout << -1, 0;
    for (int i = 1; i <= n; ++i)
      if (d[i] == -1) {
        d[i] = 1;
        break;
      }
  }
  for (int i = 1; i <= n; ++i)
    if (d[i] == -1) d[i] = 0;
  dfs(1);
  cout << ans.size() << "\n";
  for (int x : ans) cout << x << "\n";
}
