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;
int d[N];
vector<pair<int, int> > g[N];
bool active[N];
int p[N], p_edge[N];
vector<int> depth[N];
int deg[N];
int dfs(int u, int dep) {
  depth[dep].push_back(u);
  int ret = dep;
  for (int i = 0; i < (int)g[u].size(); i++) {
    int v = g[u][i].first, id = g[u][i].second;
    if (!p[v]) {
      p[v] = u;
      p_edge[v] = id;
      deg[u]++;
      deg[v]++;
      active[id] = true;
      ret = max(dep, dfs(v, dep + 1));
    }
  }
  return ret;
}
void print_ans() {
  vector<int> ans;
  for (int i = 1; i <= m; i++) {
    if (active[i]) ans.push_back(i);
  }
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < (int)ans.size(); i++) printf("%d\n", ans[i]);
}
int main() {
  int root = 1;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", d + i);
    if (d[i] == -1) root = i;
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(pair<int, int>(v, i + 1));
    g[v].push_back(pair<int, int>(u, i + 1));
  }
  p[root] = root;
  int maxdepth = dfs(root, 0);
  for (int i = maxdepth; i > 0; i--) {
    for (int j = 0; j < (int)depth[i].size(); j++) {
      int u = depth[i][j];
      if (d[u] != -1 and deg[u] % 2 != d[u]) {
        active[p_edge[u]] = false;
        deg[u]--;
        deg[p[u]]--;
      }
    }
  }
  if (d[root] != -1 and deg[root] % 2 != d[root])
    printf("-1\n");
  else
    print_ans();
  return 0;
}
