#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 300000;
const int MAX_M = 300000;
int ds[MAX_N], ses[MAX_M];
vector<pair<int, int> > nbrs[MAX_N];
int ps[MAX_N], pes[MAX_N], cis[MAX_N];
bool used[MAX_N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int cm = 0, co = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", ds + i);
    if (ds[i] < 0)
      cm++;
    else if (ds[i] > 0)
      co++;
  }
  co &= 1;
  if (co && !cm) {
    puts("-1");
    return 0;
  }
  for (int i = 0; i < n; i++)
    if (ds[i] < 0) ds[i] = co, co = 0;
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    nbrs[u].push_back(pair<int, int>(v, i));
    nbrs[v].push_back(pair<int, int>(u, i));
  }
  int k = 0;
  ps[0] = pes[0] = -1, used[0] = true;
  for (int u = 0; u >= 0;) {
    vector<pair<int, int> > &nbru = nbrs[u];
    if (cis[u] < nbru.size()) {
      pair<int, int> e = nbru[cis[u]++];
      int v = e.first, ei = e.second;
      if (!used[v]) {
        ps[v] = u, pes[v] = ei, used[v] = true;
        u = v;
      }
    } else {
      int up = ps[u];
      if (up >= 0 && ds[u]) {
        ds[up] ^= 1;
        ses[k++] = pes[u];
      }
      u = up;
    }
  }
  printf("%d\n", k);
  for (int i = 0; i < k; i++) printf("%d\n", ses[i] + 1);
  return 0;
}
