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 t;
  int num;
};
vector<edge> g[300010];
int d[300010];
int n, m;
int r[300010];
int vis[300010];
int ans[300010];
int sum;
int dfs(int v, int f) {
  for (int i = 0; i < g[v].size(); i++) {
    int w = g[v][i].t;
    if (w == f) continue;
    if (d[w] == -1) {
      r[g[v][i].num] = 1;
      sum++;
      ans[v]++;
      return 1;
    }
    if (ans[w] % 2 != d[w]) {
      if (r[g[v][i].num] == 1) {
        ans[w]--;
        ans[v]--;
        sum--;
        r[g[v][i].num] = 0;
      }
      if (r[g[v][i].num] == 0) {
        ans[w]++;
        ans[v]++;
        sum++;
        r[g[v][i].num] = 1;
      }
      return 1;
    }
  }
  for (int i = 0; i < g[v].size(); i++) {
    int w = g[v][i].t;
    if (w == f) continue;
    if (r[g[v][i].num] == 1) {
      ans[w]--;
      ans[v]--;
      r[g[v][i].num] = 0;
      if (dfs(w, v)) {
        sum--;
        return 1;
      }
      r[g[v][i].num] = 1;
      ans[w]++;
      ans[v]++;
    } else {
      ans[w]++;
      ans[v]++;
      r[g[v][i].num] = 1;
      if (dfs(w, v)) {
        sum++;
        return 1;
      }
      r[g[v][i].num] = 0;
      ans[w]--;
      ans[v]--;
    }
  }
  return 0;
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    sum = 0;
    memset(r, 0, sizeof(r));
    memset(ans, 0, sizeof(ans));
    for (int i = 0; i <= n; i++) g[i].clear();
    for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
    int u, v;
    for (int i = 1; i <= m; i++) {
      scanf("%d%d", &u, &v);
      edge e;
      e.num = i;
      e.t = v;
      g[u].push_back(e);
      e.t = u;
      g[v].push_back(e);
    }
    int flag = 0;
    for (int i = n; i >= 1; i--)
      if (d[i] != -1 && ans[i] % 2 != d[i]) {
        memset(vis, 0, sizeof(vis));
        if (dfs(i, -1) != 1) {
          flag = 1;
          break;
        }
      }
    if (flag == 1)
      cout << -1 << endl;
    else {
      cout << sum << endl;
      for (int i = 1; i <= m; i++)
        if (r[i] == 1) cout << i << endl;
    }
  }
  return 0;
}
