#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:200000000")
using namespace std;
const int MAXN = 1000 * 1000;
int d[MAXN];
vector<pair<int, int> > g[MAXN];
bool was[MAXN];
vector<int> ans;
int dfs(int v) {
  if (was[v]) return -1;
  was[v] = 1;
  int sum = 0;
  for (pair<int, int> u : g[v]) {
    int res = dfs(u.first);
    if (res == -1) continue;
    if (res == 1) {
      ans.push_back(u.second);
      sum++;
    }
  }
  if (sum % 2 == 1) {
    d[v] = 1 - d[v];
  }
  return d[v];
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    scanf("%d", d + i);
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--, v--;
    g[u].push_back({v, i + 1});
    g[v].push_back({u, i + 1});
  }
  int cnt_1 = 0;
  int ind_1 = -1;
  for (int i = 0; i < n; i++) {
    cnt_1 += (d[i] == 1);
    if (d[i] == -1) {
      ind_1 = i;
    }
  }
  if (cnt_1 % 2 == 1 && ind_1 == -1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (d[i] == -1) {
      d[i] = 0;
    }
  }
  if (cnt_1 % 2 == 1) {
    d[ind_1] = 1;
  }
  dfs(0);
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
