#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1000 * 100 + 10;
int n, m, a[N], parent[N];
vector<pair<int, int> > adj[N];
bool bad[N], mark[N], f, cnt[N];
void readInput() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    adj[a].push_back(make_pair(b, i));
    adj[b].push_back(make_pair(a, i));
  }
  return;
}
void DFS(int v) {
  mark[v] = true;
  if (f && v != 0) cnt[parent[v]] = !cnt[parent[v]];
  for (int i = 0; i < (int)adj[v].size(); i++) {
    int u = adj[v][i].first, edge = adj[v][i].second;
    if (!mark[u]) {
      parent[u] = edge;
      DFS(u);
    }
  }
  if (bad[v]) f = !f;
  if (f) cnt[parent[v]] = !cnt[parent[v]];
  return;
}
int main() {
  readInput();
  int c = 0, p = -1;
  for (int i = 0; i < n; i++) {
    if ((int)adj[i].size() % 2 != a[i] && a[i] != -1) {
      bad[i] = true;
      c++;
    }
    if (a[i] == -1) p = i;
  }
  if (c % 2 == 1 && p == -1) {
    printf("-1\n");
    return 0;
  }
  if (c % 2 == 1) bad[p] = true;
  DFS(0);
  int counter = 0;
  for (int i = 0; i < m; i++)
    if (!cnt[i]) counter++;
  printf("%d\n", counter);
  for (int i = 0; i < m; i++)
    if (!cnt[i]) printf("%d\n", i + 1);
  return 0;
}
