#include <bits/stdc++.h>
using namespace std;
const long double E = 2.71828182845904523536;
const long double pi = acos(-1);
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const long long inf = 1LL << 30;
const int N = 300300;
bool vis[N], root[N];
vector<int> adj[N];
int deg[N], a[N];
vector<int> ans;
map<pair<int, int>, int> id;
set<int> is[N];
void DFS(int u, int p) {
  if (vis[u]) return;
  vis[u] = 1;
  for (auto v : adj[u]) {
    if (v == p || root[v]) continue;
    DFS(v, u);
    if (deg[v] & 1) {
      if (a[v] == 0) {
        deg[v]++;
        deg[u]++;
        is[u].insert(v);
        is[v].insert(u);
      }
    } else {
      if (a[v] == 1) {
        deg[v]++;
        deg[u]++;
        is[u].insert(v);
        is[v].insert(u);
      }
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == -1) root[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
    id[{v, u}] = id[{u, v}] = i;
  }
  for (int i = 1; i <= n; i++)
    if (root[i]) DFS(i, 0);
  DFS(1, 0);
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1) continue;
    if (deg[i] % 2 != a[i]) {
      printf("-1\n");
      return 0;
    }
  }
  for (int i = 1; i <= n; i++)
    for (auto j : is[i])
      if (i < j) ans.push_back(id[{i, j}]);
  printf("%d\n", ans.size());
  for (auto x : ans) printf("%d\n", x);
  return 0;
}
