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>
using namespace std;
const int maxn = 3e5 + 7;
struct Edge {
  int u, v, id;
};
vector<Edge> G[maxn];
vector<Edge> es;
vector<int> ans;
vector<int> tree;
int in[maxn], n, m, d[maxn];
bool vis[maxn], vise[maxn];
bool check() {
  for (int i = 0; i < tree.size(); i++) {
    if (!vis[tree[i]]) return false;
  }
  return true;
}
bool dfs(int pos) {
  vis[pos] = 1;
  if (check()) return true;
  for (int i = 0; i < G[pos].size(); i++) {
    int v = G[pos][i].v;
    if (vis[v]) continue;
    if (dfs(v)) {
      vise[G[pos][i].id] = 1;
      return true;
    }
  }
  vis[pos] = 0;
  return false;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", d + i);
  int u, v;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &u, &v);
    in[u]++, in[v]++;
    es.push_back(Edge{u, v, i});
    G[u].push_back(Edge{u, v, i});
    G[v].push_back(Edge{u, v, i});
  }
  for (int i = 1; i <= n; i++) {
    vis[i] = 1;
    if (d[i] == -1 || d[i] == 1) vis[i] = 0;
    if (d[i] == 1) tree.push_back(i);
  }
  bool flag = false;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      flag = dfs(i);
      if (flag) break;
    }
  }
  if (flag) {
    for (int i = 0; i < m; i++) {
      if (vise[es[i].id]) ans.push_back(es[i].id);
    }
    printf("%d\n", ans.size());
    for (int i = 0; i < ans.size(); i++) {
      printf("%d\n", ans[i]);
    }
  } else
    puts("-1");
  return 0;
}
