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 MAXN = 300005;
const int MAXM = MAXN;
struct Edge {
  int to, next, id;
} e[MAXM << 1];
int head[MAXN], te = 1;
inline void addE(int u, int v, int id) {
  e[++te] = (Edge){v, head[u], id}, head[u] = te;
}
struct Road {
  int u, v;
} r[MAXM];
int from[MAXN];
int find(int x) { return (from[x] == x ? x : from[x] = find(from[x])); }
inline void Union(int u, int v) { from[find(v)] = find(u); }
int d[MAXN], cnt[MAXN];
vector<int> res;
int n, m, u, v, cur;
void dfs(int u, int fa, int id) {
  for (int j = head[u]; j != 0; j = e[j].next) {
    int v = e[j].to;
    if (v != fa) dfs(v, u, e[j].id);
  }
  if (d[u] == 1) {
    res.push_back(id);
    d[fa] ^= 1;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    if (d[i] == -1)
      cnt[2]++, cur = i;
    else
      cnt[d[i]]++;
  }
  for (int i = 1; i <= m; i++) cin >> r[i].u >> r[i].v;
  if (cnt[1] % 2 == 1 && cnt[2] == 0) {
    cout << "-1" << endl;
    exit(0);
  }
  if (cnt[1] % 2 == 1) {
    for (int i = 1; i <= n; i++)
      if (d[i] == -1) d[i] = (i == cur ? 1 : 0);
  } else {
    for (int i = 1; i <= n; i++)
      if (d[i] == -1) d[i] = 0;
  }
  for (int i = 1; i <= n; i++) from[i] = i;
  for (int i = 1; i <= m; i++)
    if (find(r[i].u) != find(r[i].v)) {
      addE(r[i].u, r[i].v, i);
      addE(r[i].v, r[i].u, i);
      Union(r[i].u, r[i].v);
    }
  dfs(1, -1, -1);
  cout << (int)res.size() << endl;
  for (int i = 0; i < res.size(); i++) cout << res[i] << endl;
  return 0;
}
