#include <bits/stdc++.h>
using namespace std;
long long n, m, st, u, jk, v, a[300005];
bool used[300005];
vector<long long> ans;
vector<pair<long long, long long> > g[300005];
long long dfs(long long x, long long r) {
  long long c = 0;
  used[x] = true;
  for (int i = 0; i < g[x].size(); i++) {
    if (!used[g[x][i].first]) {
      c += dfs(g[x][i].first, g[x][i].second);
    }
  }
  if (r != -1) {
    if ((c % 2) != a[x]) {
      ans.push_back(r);
      return 1;
    } else {
      return 0;
    }
  } else {
    if (st != 0) return 1;
    if ((c % 2) != a[x]) {
      return 0;
    } else {
      return 1;
    }
  }
}
int main() {
  scanf("%I64d%I64d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    if ((a[i] == -1) && (st != 0)) {
      a[i] = 0;
    } else if (a[i] == -1) {
      st = i;
    }
  }
  for (int i = 1; i <= m; i++) {
    scanf("%I64d%I64d", &u, &v);
    g[u].push_back(make_pair(v, i));
    g[v].push_back(make_pair(u, i));
  }
  if (st > 0) {
    jk = dfs(st, -1);
  } else {
    jk = dfs(1, -1);
  }
  if (jk == 0) {
    printf("-1");
  } else {
    printf("%d", ans.size());
    printf("\n");
    for (int i = 0; i < ans.size(); i++) {
      printf("%I64d", ans[i]);
      printf("\n");
    }
  }
  return 0;
}
