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 = 3e5 + 5;
int n, m;
int d[N], deg[N];
bool pres[N], vis[N], impo;
pair<int, int> ed[N];
vector<vector<pair<int, int> > > gr(N);
int par[N], dar[N];
set<pair<int, int> > sett;
int find(int x) {
  if (par[x] <= -1) return x;
  return par[x] = find(par[x]);
}
int merg(int a, int b) {
  if (par[a] < par[b]) {
    par[a] += par[b];
    par[b] = a;
  } else {
    par[b] += par[a];
    par[a] = b;
  }
}
void sp_tree() {
  memset(par, -1, sizeof(par));
  for (int i = 0; i < m; i++) {
    int a = ed[i].first, b = ed[i].second;
    int c = find(a), d = find(b);
    if (c != d) {
      pres[i] = 1;
      merg(c, d);
    }
  }
}
int dfs(int x) {
  vis[x] = 1;
  int ans = 0;
  for (auto it : gr[x]) {
    if (!vis[it.first]) {
      par[it.first] = x;
      dar[it.first] = it.second;
      ans += dfs(it.first);
    }
  }
  if (d[x] != -1 and deg[x] % 2 != d[x]) {
    ans++;
  }
  ans %= 2;
  if (ans) {
    if (par[x] == 0) {
      if (d[x] != -1) {
        impo = 1;
        printf("%d\n", -1);
      }
      return 0;
    }
    pres[dar[x]] ^= 1;
  }
  if (d[x] == -1) ans = 0;
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", d + i + 1);
  }
  int f_1 = 0, found = 0;
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    ed[i] = make_pair(u, v);
    deg[u]++;
    deg[v]++;
  }
  if (n == 1) {
    if (d[1] == -1 or d[1] == 0)
      printf("%d\n", 0);
    else
      printf("%d\n", -1);
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (d[i] == -1) {
      f_1 = i;
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (d[i] != -1 and deg[i] % 2 != d[i]) {
      if (!f_1) f_1 = i;
      found = 1;
      break;
    }
  }
  if (!found) {
    printf("%d\n", m);
    for (int i = 0; i < m; i++) printf("%d ", i + 1);
    printf("\n");
    return 0;
  }
  if (!f_1) f_1 = 1;
  sp_tree();
  memset(deg, 0, sizeof(deg));
  for (int i = 0; i < m; i++) {
    if (!pres[i]) continue;
    int a = ed[i].first, b = ed[i].second;
    gr[a].push_back(make_pair(b, i));
    gr[b].push_back(make_pair(a, i));
    deg[a]++;
    deg[b]++;
  }
  memset(par, 0, sizeof(par));
  dfs(f_1);
  if (impo) return 0;
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (pres[i]) ans++;
  }
  printf("%d\n", ans);
  for (int i = 0; i < m; i++) {
    if (pres[i]) printf("%d ", i + 1);
  }
  printf("\n");
}
