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 LEN = 300005;
int d[LEN], eu[LEN], ev[LEN], vis[LEN], pa[LEN], s[LEN];
vector<int> G[LEN];
map<int, int> G_m[LEN];
vector<int> ans;
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < ((int)(G[u]).size()); i++) {
    int v = G[u][i];
    if (!vis[v]) {
      if (s[v] % 2 == 1) ans.push_back(G_m[u][v]);
      dfs(v);
    }
  }
  return;
}
int dfs_sum(int u) {
  s[u] = d[u];
  vis[u] = 1;
  for (int i = 0; i < ((int)(G[u]).size()); i++) {
    int v = G[u][i];
    if (!vis[v]) {
      s[u] += dfs_sum(v);
    }
  }
  return s[u];
}
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) == 2) {
    for (int i = 0; i < n; i++) scanf("%d", d + i);
    for (int i = 0; i < m; i++) scanf("%d%d", eu + i, ev + i);
    for (int i = 0; i < m; i++) eu[i]--, ev[i]--;
    int cnt = 0, z = -1, src = -1;
    for (int i = 0; i < n; i++)
      cnt += (d[i] == 1), z = (d[i] == -1) ? i : z, src = (d[i] == 1) ? i : src;
    for (int i = 0; i < n; i++) G[i].clear();
    for (int i = 0; i < n; i++) G_m[i].clear();
    for (int i = 0; i < m; i++) {
      G[eu[i]].push_back(ev[i]);
      G[ev[i]].push_back(eu[i]);
      G_m[eu[i]][ev[i]] = i + 1;
      G_m[ev[i]][eu[i]] = i + 1;
    }
    if (cnt % 2 == 1 && z == -1) {
      printf("-1\n");
      continue;
    }
    if (src == -1) {
      printf("0\n");
      continue;
    }
    if (cnt % 2 == 1) d[z] = 1;
    for (int i = 0; i < n; i++)
      if (d[z] == -1) d[z] = 0;
    ans.clear();
    for (int i = 0; i < n; i++) vis[i] = 0;
    dfs_sum(src);
    for (int i = 0; i < n; i++) vis[i] = 0;
    dfs(src);
    printf("%d\n", ((int)(ans).size()));
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ((int)(ans).size()); i++)
      printf(i ? " %d" : "%d", ans[i]);
    printf("\n");
  }
  return 0;
}
