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;
struct Edge {
  int u, ind;
  Edge(int u, int ind) : u(u), ind(ind) {}
};
const int MAXN = 3e5;
int d[MAXN];
bool used[MAXN];
int color[MAXN];
vector<Edge> edges[MAXN];
bool use_edge[MAXN];
int cnt_vert[MAXN];
bool dfs(int v) {
  if (d[v] == -1 || color[v] == d[v]) return true;
  used[v] = true;
  color[v] = !color[v];
  for (; cnt_vert[v] < edges[v].size(); cnt_vert[v]++) {
    Edge elem = edges[v][cnt_vert[v]];
    if (!used[elem.u]) {
      use_edge[elem.ind] = !use_edge[elem.ind];
      color[elem.u] = !color[elem.u];
      if (dfs(elem.u)) return true;
      color[elem.u] = !color[elem.u];
      use_edge[elem.ind] = !use_edge[elem.ind];
    }
  }
  color[v] = !color[v];
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> d[i];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    edges[u].push_back({v, i});
    edges[v].push_back({u, i});
  }
  for (int i = 0; i < n; i++) {
    if (d[i] != -1 && color[i] != d[i]) {
      fill(used, used + n, false);
      if (!dfs(i)) {
        cout << "-1\n";
        return 0;
      }
    }
  }
  vector<int> ans;
  for (int i = 0; i < m; i++)
    if (use_edge[i]) ans.push_back(i);
  cout << ans.size() << '\n';
  for (int elem : ans) cout << elem + 1 << '\n';
  return 0;
}
