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;
int n, m;
int d[300500];
vector<pair<int, int> > E[300500];
set<int> ans;
int deg[300500];
bool vis[300500];
int dfs1(int x, int p) {
  int cnt = 0;
  int dd = 0;
  vis[x] = true;
  for (auto e : E[x])
    if (!vis[e.first]) {
      cnt++;
      int res = dfs1(e.first, x);
      if (res == 1) {
        ans.insert(e.second);
        dd += 1;
      }
    }
  if (cnt == 0) {
    if (d[x] == 1) return 1;
    if (d[x] == -1) return 0;
    if (d[x] == 0) return 0;
  }
  if (d[x] == -1) return 0;
  if (d[x] == 0) {
    if (dd % 2 == 0)
      return 0;
    else
      return 1;
  }
  if (d[x] == 1) {
    if (dd % 2 == 1)
      return 0;
    else
      return 1;
  }
}
int dfs2(int x) {
  vis[x] = true;
  if (d[x] == -1) return 1;
  for (auto e : E[x])
    if (!vis[e.first]) {
      if (ans.find(e.second) != ans.end()) continue;
      int res = dfs2(e.first);
      if (res == 1) {
        ans.insert(e.second);
        return 1;
      }
    }
  return 0;
}
int main(void) {
  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);
    E[a].push_back({b, i});
    E[b].push_back({a, i});
  }
  memset(vis, 0, sizeof vis);
  int res = dfs1(1, -1);
  if (res == 0) {
    printf("%d\n", ans.size());
    for (auto e : ans) printf("%d\n", e);
    return 0;
  }
  memset(vis, 0, sizeof vis);
  res = dfs2(1);
  if (res == 1) {
    printf("%d\n", ans.size());
    for (auto e : ans) printf("%d\n", e);
    return 0;
  }
  printf("-1");
}
