#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void umin(T &a, T b) {
  a = min(a, b);
}
template <class T>
inline void umax(T &a, T b) {
  a = max(a, b);
}
const int INF = 0x3f3f3f3f;
long long mod = 1e9 + 7;
const int N = 300005;
int a[N];
vector<pair<int, int> > G[N];
vector<int> ans;
int c[N];
int vis[N];
int ok;
void dfs(int u, int g, int fa) {
  vis[u] = 1;
  for (auto x : G[u]) {
    int id = x.second;
    int v = x.first;
    if (vis[v]) continue;
    dfs(v, id, u);
  }
  if (a[u] != -1) {
    if (c[u] % 2 != a[u]) {
      if (fa == -1)
        ok = 0;
      else {
        c[fa]++;
        ans.push_back(g);
      }
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int sb = 0, sum = 0;
  ;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == -1) {
      sb = i;
    } else {
      sum += a[i];
    }
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back({v, i});
    G[v].push_back({u, i});
  }
  ok = 1;
  if (sb) {
    dfs(sb, -1, -1);
  } else {
    dfs(1, -1, -1);
  }
  if (!ok) {
    puts("-1");
    return 0;
  }
  printf("%d\n", ans.size());
  for (auto x : ans) {
    printf("%d ", x);
  }
  return 0;
}
