#include <bits/stdc++.h>
using namespace std;
struct data {
  int e, cnt;
  int num;
  data(int E, int CNT, int NUM) : e(E), cnt(CNT), num(NUM) {}
};
vector<data> li[300001];
int edges[300001];
int ind[300001];
int TAG;
int dfs(int s) {
  if (ind[s] == 1 || ind[s] == -1) return s;
  for (int T = 1; T >= 0; T--) {
    for (int i = 0; i < li[s].size(); i++) {
      data next = li[s][i];
      int ns = next.e;
      int j = next.num;
      if (ind[ns] != T && ind[ns] != -T) continue;
      if (edges[j] == TAG) continue;
      li[s][i].cnt += 1;
      edges[j] = TAG;
      int temp = dfs(ns);
      if (temp != -1) return temp;
      li[s][i].cnt -= 1;
    }
  }
  return -1;
}
int main() {
  int n, m;
  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);
    li[u].push_back(data(v, 0, i));
    li[v].push_back(data(u, 0, i));
  }
  for (int i = 1; i <= n; i++) {
    if (ind[i] == 1) {
      ind[i] = 0;
      TAG = i;
      int j = dfs(i);
      if (j == -1) {
        printf("-1\n");
        return 0;
      }
      ind[j] = ind[j] == -1 ? -1 : 0;
    }
  }
  for (int i = 1; i <= m; i++) edges[i] = 0;
  vector<int> ans;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < li[i].size(); j++) {
      if (li[i][j].cnt % 2 == 1) edges[li[i][j].num] += 1;
    }
  for (int i = 1; i <= m; i++)
    if (edges[i] % 2 == 1) ans.push_back(i);
  printf("%lu\n", ans.size());
  for (int i = 0; i < ans.size(); i++) printf("%d\n", ans[i]);
  return 0;
}
