#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int v, id;
};
vector<Edge> edges[300008];
int d[300008], ans[300008];
bool vis[300008];
void dfs(int u, int fa, int id) {
  for (int i = 0; i < (int)edges[u].size(); i++) {
    Edge to = edges[u][i];
    if (!vis[to.v]) {
      vis[to.v] = true;
      dfs(to.v, u, to.id);
    }
  }
  if (d[u] == 1) {
    d[u] = 0;
    d[fa] = 1 - d[fa];
    ans[id] = 1;
  }
}
int main() {
  int n, m, k;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    edges[i].clear();
    scanf("%d", &d[i]);
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edges[u].push_back((Edge){v, i});
    edges[v].push_back((Edge){u, i});
    ans[i] = 0;
  }
  int sum = 0, neg = 0;
  for (int i = 1; i <= n; i++) {
    if (d[i] == -1)
      neg = 1;
    else
      sum += d[i];
  }
  if ((sum & 1) && !neg)
    printf("-1");
  else {
    for (int i = 1; i <= n; i++) {
      if (d[i] == -1) {
        if (sum & 1) {
          d[i] = 1;
          sum = 0;
        } else
          d[i] = 0;
      }
      vis[i] = false;
    }
    dfs(1, -1, -1);
    k = 0;
    for (int i = 1; i <= m; i++) {
      if (ans[i]) ++k;
    }
    printf("%d\n", k);
    for (int i = 1; i <= m; i++) {
      if (ans[i]) printf("%d\n", i);
    }
  }
  return 0;
}
