#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, n;
  Edge(int to, int n) : to(to), n(n) {}
};
typedef Edge* e;
const int MAXN = 1e6;
bool used[MAXN];
bool used_edge[MAXN];
vector<e> gr[MAXN];
vector<e> tree[MAXN];
int par[MAXN];
int need[MAXN];
inline void dfs(int v) {
  used[v] = 1;
  for (auto ee : gr[v]) {
    int u = ee->to;
    int num = ee->n;
    if (!used[u]) {
      dfs(u);
      used_edge[num] = 1;
      par[u] = num;
      tree[v].push_back(ee);
    }
  }
}
inline int dfs_tree(int v, int p) {
  int pp = (p != -1);
  for (auto ee : tree[v]) {
    pp += dfs_tree(ee->to, v);
  }
  if (need[v] == -1 || need[v] == pp % 2) {
    return 1;
  } else {
    if (p != -1) {
      used_edge[par[v]] = 0;
    }
    return 0;
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int p, q;
  int root = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &need[i]);
    if (need[i] == -1) {
      root = i;
    }
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &p, &q);
    --p;
    --q;
    gr[p].push_back(new Edge(q, i));
    gr[q].push_back(new Edge(p, i));
  }
  dfs(root);
  if (dfs_tree(root, -1)) {
    vector<int> ans;
    for (int i = 0; i < m; ++i) {
      if (used_edge[i]) {
        ans.push_back(i + 1);
      }
    }
    printf("%d\n", ans.size());
    for (int u : ans) {
      printf("%d\n", u);
    }
  } else {
    printf("-1\n");
  }
}
