#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 9;
const long long MOD = 1e9 + 7;
vector<pair<int, int> > g[MAX];
vector<int> res;
int d[MAX];
bool vis[MAX];
void dfs(int v, int par, int e) {
  vis[v] = true;
  for (auto x : g[v]) {
    int u = x.first;
    int id = x.second;
    if (vis[u]) continue;
    dfs(u, v, id);
  }
  if (par == -1) return;
  if (d[v] == 0) return;
  res.push_back(e);
  d[par] = 1 - d[par];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int o = 0, neg = 0;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    if (d[i] == 1) o++;
    if (d[i] == -1) neg++;
  }
  if (o % 2 == 1) {
    if (neg == 0) return cout << "-1\n", 0;
    for (int i = 0; i < n; i++)
      if (d[i] == -1) {
        if (neg != 0) {
          neg = 0;
          d[i] = 1;
        } else
          d[i] = 0;
      }
  } else
    for (int i = 0; i < n; i++)
      if (d[i] == -1) d[i] = 0;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    v--, u--;
    g[v].push_back({u, i + 1});
    g[u].push_back({v, i + 1});
  }
  dfs(0, -1, -1);
  cout << res.size() << "\n";
  for (auto x : res) cout << x << " ";
  cout << "\n";
}
