#include <bits/stdc++.h>
using namespace std;
const int maxN = 300005;
int n, m;
int d[maxN];
int vis[maxN];
int root;
vector<int> adj[maxN];
vector<int> id[maxN];
vector<int> res;
int dfs(int cur) {
  if (vis[cur]++) return 0;
  int p = 0;
  for (int i = 0; i < adj[cur].size(); i++) {
    int v = adj[cur][i];
    int t = id[cur][i];
    if (dfs(v)) {
      res.push_back(t);
      p ^= 1;
    }
  }
  if (d[cur] != -1 && p != d[cur]) return 1;
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  root = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    if (d[i] == -1) root = i;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    id[u].push_back(i);
    adj[v].push_back(u);
    id[v].push_back(i);
  }
  if (dfs(root)) {
    printf("-1\n");
    return 0;
  }
  cout << res.size() << endl;
  for (int i = 0; i < res.size(); i++) printf("%d\n", res[i]);
  return 0;
}
