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 dest, num;
};
int n, m, f[300005];
int cnt, ans[300005];
int root, d[300005];
vector<edge> a[300005];
void work(int pos, int fa) {
  for (unsigned i = 0; i < a[pos].size(); i++) {
    if (a[pos][i].dest == fa) continue;
    work(a[pos][i].dest, pos);
    if (d[a[pos][i].dest] == 1) {
      ans[++cnt] = a[pos][i].num;
      if (d[pos] != -1) d[pos] ^= 1;
    }
  }
}
int F(int x) {
  if (f[x] == x)
    return x;
  else
    return f[x] = F(f[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    f[i] = i;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (F(x) == F(y)) continue;
    f[F(x)] = F(y);
    a[x].push_back((edge){y, i});
    a[y].push_back((edge){x, i});
  }
  root = 1;
  for (int i = 1; i <= n; i++)
    if (d[i] == -1) {
      root = i;
      break;
    }
  work(root, 0);
  if (d[root] == 1)
    printf("-1\n");
  else {
    printf("%d\n", cnt);
    for (int i = 1; i <= cnt; i++) printf("%d ", ans[i]);
    printf("\n");
  }
  return 0;
}
