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 = 1 << 19;
bool vis[N];
vector<int> g[N], res;
int n, m, d[N], x[N], y[N];
void dfs(int u) {
  vis[u] = 1;
  if (d[u] == -1) d[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    int id = g[u][i];
    int v = x[id] == u ? y[id] : x[id];
    if (!vis[v]) {
      dfs(v), d[u] ^= d[v];
      if (d[v]) res.push_back(id);
    }
  }
}
void output() {
  cout << res.size() << endl;
  for (int i = 0; i < res.size(); i++) printf("%d\n", res[i]);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", d + i);
  for (int i = 1; i <= m; i++)
    scanf("%d%d", x + i, y + i), g[x[i]].push_back(i), g[y[i]].push_back(i);
  for (int i = 1; i <= n; i++)
    if (d[i] == -1) {
      dfs(i);
      output();
      return 0;
    }
  dfs(1);
  if (d[1])
    puts("-1");
  else
    output();
}
