#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
const double eps = 1e-10;
const int N = 3e5 + 5;
int n, m, d[N], res[N], cnt;
vector<pair<int, int> > g[N];
bool vis[N];
void dfs(int u) {
  vis[u] = true;
  for (int i = 0; i < g[u].size(); i++) {
    pair<int, int> &e = g[u][i];
    int &v = e.first;
    if (vis[v]) continue;
    dfs(v);
    if (d[v] == 1) {
      if (~d[u]) d[u] ^= 1;
      d[v] = 0, res[cnt++] = e.second;
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  int s = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", d + i);
    if (d[i] == -1) s = i;
  }
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d %d", &u, &v);
    g[u].push_back(pair<int, int>(v, i));
    g[v].push_back(pair<int, int>(u, i));
  }
  dfs(s);
  if (~d[s] && d[s]) {
    puts("-1");
    return 0;
  }
  printf("%d\n", cnt);
  while (cnt--) printf("%d\n", res[cnt]);
  return 0;
}
