#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3e5 + 5;
struct Edge {
  int to, id;
};
struct Node {
  int dep, id;
  Node() {}
  Node(int dep_, int id_) : dep(dep_), id(id_) {}
  bool operator<(const Node &b) const { return dep < b.dep; }
};
int N, M;
int d[MAX_N];
vector<Edge> G[MAX_N];
int fa[MAX_N];
int en[MAX_N];
bool vis[MAX_N];
priority_queue<Node> que;
vector<int> ans;
bool inque[MAX_N];
int dep[MAX_N];
void addEdge(int a, int b, int id) {
  G[a].push_back((Edge){b, id});
  G[b].push_back((Edge){a, id});
}
void dfs(int v) {
  bool isLeaf = true;
  for (int i = 0; i < G[v].size(); ++i) {
    Edge &e = G[v][i];
    if (!vis[e.to]) {
      vis[e.to] = true;
      fa[e.to] = v;
      dep[e.to] = dep[v] + 1;
      en[e.to] = e.id;
      dfs(e.to);
      isLeaf = false;
    }
  }
  if (isLeaf) {
    que.push(Node(dep[v], v));
    inque[v] = true;
  }
}
void dfs2(int v, int p, int eid) {
  for (auto e : G[v]) {
    if (!vis[e.to]) {
      vis[e.to] = true;
      dfs2(e.to, v, e.id);
    }
  }
  if (d[v] == 1) {
    ans.push_back(eid);
    d[p] ^= 1;
  }
}
void solve() {
  while (!que.empty()) {
    Node v = que.top();
    que.pop();
    inque[v.id] = false;
    if (d[v.id] == 1) {
      d[fa[v.id]] ^= 1;
      if (!inque[fa[v.id]]) {
        que.push(Node(dep[fa[v.id]], fa[v.id]));
        inque[fa[v.id]] = true;
      }
      ans.push_back(en[v.id]);
    } else if (fa[v.id] != -1) {
      if (!inque[fa[v.id]]) {
        que.push(Node(dep[fa[v.id]], fa[v.id]));
        inque[fa[v.id]] = true;
      }
    }
  }
  printf("%u\n", ans.size());
  for (int i = 0; i < ans.size(); ++i) {
    printf("%d\n", ans[i]);
  }
}
int main() {
  cin >> N >> M;
  int sumD = 0, numn1 = 0, idxn1;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &d[i]);
    if (d[i] != -1)
      sumD += d[i];
    else
      numn1++, idxn1 = i;
  }
  for (int i = 0; i < M; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    addEdge(a, b, i + 1);
  }
  if (numn1 == 0 && sumD % 2 == 1) {
    printf("-1\n");
    return 0;
  }
  if (sumD % 2 == 1) {
    d[idxn1] = 1;
  }
  for (int i = 0; i < N; ++i) {
    if (d[i] == -1) d[i] = 0;
  }
  fa[0] = -1;
  vis[0] = true;
  dfs(0);
  solve();
  return 0;
}
