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 N = 300010;
int n, m;
vector<int> g[N], st[N];
vector<pair<int, int> > ed;
map<pair<int, int>, int> loc;
set<int> edind;
int d[N], p[N], par[N], deg[N];
int neg1 = 0;
int root, sum;
int find(int x) { return x == p[x] ? x : (p[x] = find(p[x])); }
void dfs(int x, int pp) {
  for (int ch : st[x]) {
    if (ch != pp) dfs(ch, x);
  }
  if (deg[x] % 2 != d[x]) {
    edind.erase(loc[{min(x, pp), max(x, pp)}]);
    deg[x]--;
    deg[pp]--;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 1; i < N; i++) p[i] = i;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    if (d[i] != -1) sum += d[i];
    if (d[i] == -1) neg1 = i;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
    ed.push_back({u, v});
  }
  if (sum % 2 == 1 && neg1 == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (d[i] == -1) {
      if (sum % 2 == 1) {
        d[i] = 1;
        sum++;
      } else {
        d[i] = 0;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    pair<int, int> e = ed[i];
    int u = e.first, v = e.second;
    if (find(u) != find(v)) {
      p[find(u)] = find(v);
      deg[u]++;
      deg[v]++;
      st[u].push_back(v);
      st[v].push_back(u);
      edind.insert(i);
      loc[{min(u, v), max(u, v)}] = i;
    }
  }
  dfs(1, 0);
  cout << edind.size() << endl;
  for (auto ind : edind) {
    cout << ind + 1 << endl;
  }
  return 0;
}
