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;
int n, m;
pair<pair<int, int>, int> e[300005];
vector<pair<int, int> > adj[300005];
int p[300005];
int d[300005];
bool t[300005];
int get_par(int x) {
  if (p[x] == x) return x;
  return p[x] = get_par(p[x]);
}
void dfs(int i, int p, int in) {
  for (auto j : adj[i])
    if (j.first != p) dfs(j.first, i, j.second);
  if (d[i]) {
    t[in] = 1;
    d[p] ^= 1;
  }
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  int xs = 0, cnt = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    if (d[i] != -1)
      xs += d[i];
    else
      cnt++;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d", &x);
    scanf("%d", &y);
    e[i] = {{x, y}, i};
  }
  if (cnt < (xs % 2)) {
    printf("%d\n", -1);
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (xs % 2 && d[i] == -1)
      d[i] = 1;
    else if (d[i] == -1)
      d[i] = 0;
  }
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= m; i++) {
    int x = e[i].first.first;
    int y = e[i].first.second;
    int j = e[i].second;
    if (get_par(x) != get_par(y)) {
      p[get_par(x)] = get_par(y);
      adj[x].push_back({y, j});
      adj[y].push_back({x, j});
    }
  }
  dfs(1, 1, 0);
  int an = 0;
  for (int i = 1; i <= m; i++) an += t[i];
  printf("%d\n", an);
  for (int i = 1; i <= m; i++)
    if (t[i]) printf("%d\n", i);
  return 0;
}
