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 sz = 300005;
struct edge {
  int t, i;
  edge(int t, int i) : t(t), i(i) {}
};
int d[sz];
vector<edge> g[sz];
vector<int> ans, stk;
bool v[sz];
bool foo(int c, int p) {
  for (auto e : g[c]) {
    if (e.t == p || !d[e.t]) continue;
    if (v[e.i]) continue;
    v[e.i] = true;
    stk.push_back(e.i);
    return true;
  }
  for (auto e : g[c]) {
    if (e.t == p || d[e.t]) continue;
    if (foo(e.t, c)) {
      if (v[e.i]) continue;
      v[e.i] = true;
      stk.push_back(e.i);
      return true;
    }
  }
  return false;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", d + i);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(edge(b, i));
    g[b].push_back(edge(a, i));
  }
  bool ok = true;
  for (int i = 1; i <= n; i++) {
    if (d[i] != 1) continue;
    if (foo(i, 0)) continue;
    ok = false;
    break;
  }
  if (ok) {
    for (int i = 1; i <= m; i++)
      if (v[i]) ans.push_back(i);
    printf("%d\n", ans.size());
    for (int i : ans) printf("%d\n", i);
  } else
    puts("-1");
}
