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 MX = 3e5 + 5;
struct Edge {
  int v, nxt;
} E[MX * 2];
pair<int, int> edge[MX];
int a[MX], IN[MX], head[MX], tot;
void add(int u, int v) {
  E[tot].v = v;
  E[tot].nxt = head[u];
  head[u] = tot++;
}
int vis[MX], pre[MX];
vector<int> ver;
void dfs1(int u, int fa) {
  int j = -1;
  vis[u] = 1;
  for (int i = head[u]; ~i; i = E[i].nxt) {
    int v = E[i].v;
    if (v == fa || vis[v]) {
      j = i;
      continue;
    }
    dfs1(v, u);
  }
  if ((a[u] == 1 && IN[u] % 2 == 0) && fa > 0) {
    ver.push_back(j);
    IN[fa]++;
  }
  if ((a[u] == 0 && IN[u] % 2 == 1) && fa > 0) {
    ver.push_back(j);
    IN[fa]++;
  }
}
void dfs2(int u, int fa) {
  int j = -1;
  vis[u] = 1;
  for (int i = head[u]; ~i; i = E[i].nxt) {
    int v = E[i].v;
    if (v == fa || vis[v]) {
      j = i;
      continue;
    }
    dfs2(v, u);
  }
  if ((a[u] == 1 && IN[u] % 2 == 0) && fa > 0) {
    ver.push_back(j);
    IN[fa]++;
  }
  if ((a[u] == 0 && IN[u] % 2 == 1) && fa > 0) {
    ver.push_back(j);
    IN[fa]++;
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int flag = 1;
  memset(head, -1, sizeof(head));
  int rt = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == -1) rt = i;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &edge[i].first, &edge[i].second);
    add(edge[i].first, edge[i].second);
    add(edge[i].second, edge[i].first);
  }
  if (rt) {
    dfs1(rt, 0);
    sort(ver.begin(), ver.end());
    printf("%d\n", ver.size());
    for (int i = 0; i < ver.size(); i++)
      printf("%d%c", ver[i] / 2 + 1, i == ver.size() - 1 ? '\n' : ' ');
  } else {
    dfs2(1, 0);
    if (a[1] == (IN[1] % 2)) {
      sort(ver.begin(), ver.end());
      printf("%d\n", ver.size());
      for (int i = 0; i < ver.size(); i++)
        printf("%d%c", ver[i] / 2 + 1, i == ver.size() - 1 ? '\n' : ' ');
    } else
      printf("-1\n");
  }
  return 0;
}
