3 2
1 0 1
1 2
2 3
 10 10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
6 7
8 3
6 4
4 2
9 2
5 10
9 8
10 7
5 1
6 2

2
1
2
 0

#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, high[N], root[N], d[N], dep[N], ins[N];
vector<pair<int, int> > g[N];
pair<int, int> e[N];
set<int> s;
bool vis[N];
int find(int x) { return x == root[x] ? x : root[x] = find(root[x]); }
void unite(int u, int v) {
  u = find(u), v = find(v);
  if (u == v) return;
  if (high[u] < high[v])
    root[u] = v;
  else if (high[u] < high[v])
    root[v] = u;
  else
    root[u] = v, high[v]++;
}
void kruskal() {
  for (int i = 1; i <= m; i++) {
    int u = find(e[i].first), v = find(e[i].second);
    if (u != v) {
      unite(u, v), s.insert(i);
      g[u].push_back(pair<int, int>(v, i)),
          g[v].push_back(pair<int, int>(u, i));
      dep[u]++, dep[v]++;
    }
  }
}
void dfs(int u) {
  vis[u] = true;
  for (int i = 0; i < g[u].size(); i++) {
    pair<int, int> &ee = g[u][i];
    int &v = ee.first;
    if (!vis[v]) {
      dfs(v);
      if (d[v] == -1)
        ins[u] = ee.second;
      else if ((dep[v] & 1) != d[v]) {
        if (~ins[v])
          s.erase(ins[v]), dep[e[ins[v]].second]--, dep[e[ins[v]].first]--;
        else
          s.erase(ee.second), dep[v]--, dep[u]--;
      }
    }
  }
}
int main() {
  memset(ins, -1, sizeof ins);
  scanf("%d %d", &n, &m);
  int ss = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", d + i);
    if (d[i] == -1) ss = i;
    root[i] = i, high[i] = dep[i] = 0;
  }
  for (int i = 1; i <= m; i++) scanf("%d %d", &e[i].first, &e[i].second);
  kruskal();
  memset(vis, 0, sizeof vis);
  dfs(ss);
  if (~d[ss] && (dep[ss] & 1) != d[ss]) {
    if (~ins[ss])
      s.erase(ins[ss]);
    else {
      puts("-1");
      return 0;
    }
  }
  printf("%d\n", s.size());
  for (int i : s) printf("%d\n", i);
  return 0;
}
