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 = 3e5 + 10;
int n, m, ind[maxN], ans = 0;
bool take[maxN];
struct edge {
  int v, id;
} back[maxN];
vector<edge> g[maxN];
bool BFS(int st) {
  bool check = false;
  int en;
  for (int i = 1; i <= n; ++i) back[i].v = -1;
  back[st].v = 0;
  queue<int> que;
  que.push(st);
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    if ((ind[u] == -1 || ind[u]) && u != st) {
      en = u;
      check = true;
      break;
    }
    for (int i = 0; i < g[u].size(); ++i) {
      int v = g[u][i].v, id = g[u][i].id;
      if (back[v].v != -1) continue;
      back[v].v = u;
      back[v].id = g[u][i].id;
      que.push(v);
    }
  }
  if (!check) return false;
  while (en) {
    if (ind[en] != -1) ind[en] = (ind[en] + 1) % 2;
    take[back[en].id] = true;
    en = back[en].v;
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &ind[i]);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    edge tmp;
    tmp.id = i;
    tmp.v = v;
    g[u].push_back(tmp);
    tmp.v = u;
    g[v].push_back(tmp);
  }
  for (int i = 1; i <= n; ++i)
    if (ind[i] == 1) {
      bool tmp = BFS(i);
      if (!tmp) {
        printf("-1");
        return 0;
      }
    }
  for (int i = 1; i <= m; ++i) ans += (int)take[i];
  printf("%d\n", ans);
  for (int i = 1; i <= m; ++i)
    if (take[i]) printf("%d ", i);
}
