#include <bits/stdc++.h>
using namespace std;
const int maxn = 308050;
int a[maxn], flag[maxn];
bool vis[maxn];
struct node {
  int x, y;
} b[maxn];
vector<node> q[maxn];
int dfs(int x) {
  int i, ans;
  vis[x] = 1;
  ans = a[x];
  for (i = 0; i < (int)q[x].size(); i++) {
    node v = q[x][i];
    if (vis[v.x]) continue;
    if (dfs(v.x)) {
      ans ^= 1;
      flag[v.y] = 1;
    }
  }
  if (a[x] == -1) return 0;
  return ans;
}
int main() {
  int n, m, i, x, y, e1 = 0, e2 = 0, sum = 0;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == -1) e1 = i;
    if (a[i] == 1) e2++;
  }
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    node tmp;
    tmp.x = y;
    tmp.y = i;
    q[x].push_back(tmp);
    tmp.x = x;
    tmp.y = i;
    q[y].push_back(tmp);
  }
  if (e1 == 0 && e2 % 2) {
    printf("-1\n");
    return 0;
  }
  int start = max(e1, 1);
  dfs(start);
  for (i = 1; i <= m; i++) {
    if (flag[i]) sum++;
  }
  printf("%d\n", sum);
  for (i = 1; i <= m; i++) {
    if (flag[i]) printf("%d\n", i);
  }
  return 0;
}
