3 2
1 0 1
1 2
2 3
 10 10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
6 7
8 3
6 4
4 2
9 2
5 10
9 8
10 7
5 1
6 2

2
1
2
 0

#include <bits/stdc++.h>
const int sz = 300300;
int d[sz];
int n, m;
struct Edge {
  int f, t, i;
  Edge(int F, int T, int I) { f = F, t = T, i = I; }
};
bool operator<(const Edge& a, const Edge& b) {
  return d[a.f] + d[a.t] < d[b.f] + d[b.t];
}
std::vector<Edge> g[sz];
int depth[sz];
std::vector<Edge> edges;
std::vector<Edge> ansG[sz];
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    std::cin >> d[i];
  }
  for (int i = 0; i < m; i++) {
    int f, t;
    std::cin >> f >> t;
    g[f].push_back(Edge(f, t, i + 1));
    g[t].push_back(Edge(f, t, i + 1));
    edges.push_back(Edge(f, t, i + 1));
  }
  std::queue<int> q;
  memset(depth, 0x3f, sizeof depth);
  for (int i = 1; i <= n; i++) {
    if (d[i] == -1) {
      q.push(i);
      depth[i] = 0;
    }
  }
  if (q.size() == 0) q.push(1);
  while (q.size()) {
    int v = q.front();
    q.pop();
    for (auto ed : g[v]) {
      if (depth[ed.t] > depth[ed.f] + 1) {
        depth[ed.t] = depth[ed.f] + 1;
        q.push(ed.t);
      }
    }
  }
  std::sort(edges.begin(), edges.end());
  std::reverse(edges.begin(), edges.end());
  auto good = [&](int v) {
    return ((ansG[v].size() % 2) == d[v]) || (d[v] == -1);
  };
  for (auto ed : edges) {
    int a = ed.f;
    int b = ed.t;
    if (d[a] < d[b]) std::swap(a, b);
    if (!good(a)) {
      ansG[b].push_back(ed);
      ansG[a].push_back(ed);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!good(i)) {
      std::cout << -1;
      return 0;
    }
  }
  std::vector<int> ans;
  for (int i = 1; i <= n; i++) {
    for (auto ed : ansG[i]) {
      if (ed.f == i) {
        ans.push_back(ed.i);
      }
    }
  }
  std::cout << ans.size() << std::endl;
  for (int i : ans) {
    std::cout << i << " ";
  }
  return 0;
}
