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 = 300005;
const int DEG = 25;
struct Edge {
  int to, next;
} edge[MAXN * 2];
int head[MAXN], tot;
void addedge(int u, int v) {
  edge[tot].to = v;
  edge[tot].next = head[u];
  head[u] = tot++;
}
void init() {
  tot = 0;
  memset(head, -1, sizeof(head));
}
int fa[MAXN][DEG];
int deg[MAXN];
void BFS(int root) {
  queue<int> que;
  deg[root] = 0;
  fa[root][0] = 0;
  que.push(root);
  while (!que.empty()) {
    int tmp = que.front();
    que.pop();
    for (int i = 1; i < DEG; i++) fa[tmp][i] = fa[fa[tmp][i - 1]][i - 1];
    for (int i = head[tmp]; i != -1; i = edge[i].next) {
      int v = edge[i].to;
      if (v == fa[tmp][0]) continue;
      if (fa[v][0] > 0) continue;
      deg[v] = deg[tmp] + 1;
      fa[v][0] = tmp;
      que.push(v);
    }
  }
}
int LCA(int u, int v) {
  if (deg[u] > deg[v]) swap(u, v);
  int hu = deg[u], hv = deg[v];
  int tu = u, tv = v;
  for (int det = hv - hu, i = 0; det; det >>= 1, i++)
    if (det & 1) tv = fa[tv][i];
  if (tu == tv) return tu;
  for (int i = DEG - 1; i >= 0; i--) {
    if (fa[tu][i] == fa[tv][i]) continue;
    tu = fa[tu][i];
    tv = fa[tv][i];
  }
  return fa[tu][0];
}
bool flag[MAXN];
int vertkey[MAXN];
int curstate[MAXN] = {};
int universal = -1;
int n, m;
int main() {
  memset(flag, 1, sizeof(flag));
  init();
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", vertkey + i);
    if (vertkey[i] == -1) universal = i;
  }
  int v, u;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &v, &u);
    addedge(u, v);
    addedge(v, u);
    ((curstate[u]) = (curstate[u]) == 1 ? 0 : 1);
    ((curstate[v]) = (curstate[v]) == 1 ? 0 : 1);
  }
  BFS(1);
  int curv = 1, curu = 1;
  bool okbit = true;
  while (true) {
    while (curv <= n) {
      if (vertkey[curv] == -1 || vertkey[curv] == curstate[curv])
        curv++;
      else
        break;
    }
    if (curv > n) break;
    curu = curv + 1;
    while (curu <= n) {
      if (vertkey[curu] == -1 || vertkey[curu] == curstate[curu])
        curu++;
      else
        break;
    }
    if (curu > n) {
      if (universal == -1) {
        okbit = false;
        break;
      } else
        curu = universal;
    }
    int lca = LCA(curv, curu);
    for (int p = curv; p != lca; p = fa[p][0]) {
      for (int q = head[p]; q != 0; q = edge[q].next) {
        if (edge[q].to == fa[p][0]) {
          ((flag[q / 2 + 1]) = (flag[q / 2 + 1]) == 1 ? 0 : 1);
          break;
        }
      }
    }
    for (int p = curu; p != lca; p = fa[p][0]) {
      for (int q = head[p]; q != 0; q = edge[q].next) {
        if (edge[q].to == fa[p][0]) {
          ((flag[q / 2 + 1]) = (flag[q / 2 + 1]) == 1 ? 0 : 1);
          break;
        }
      }
    }
    curv++;
  }
  if (okbit) {
    vector<int> res;
    for (int i = 1; i <= m; i++) {
      if (flag[i]) res.push_back(i);
    }
    cout << res.size() << endl;
    for (auto &j : res) printf("%d\n", j);
  } else {
    cout << -1 << endl;
  }
  return 0;
}
