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 in[N], has[N], leave[N], vis[N], d[N], cur[N], cur_id;
vector<pair<int, int> > adj[N];
int n, m;
bool solve(int u, int root) {
  if (cur[u] == cur_id) return false;
  cur[u] = cur_id;
  if (u != root) {
    if (has[u]) {
      has[u] = 0;
      return 1;
    }
  }
  for (pair<int, int> nxt : adj[u]) {
    if (!vis[nxt.first] && solve(nxt.first, root)) {
      leave[nxt.second] ^= 1;
      return true;
    }
    vis[nxt.first] = 1;
  }
  return false;
}
int main() {
  int sol = 0, problem = 0;
  int u, v;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < int(n); i++) scanf("%d", &d[i]);
  for (int i = 0; i < int(n); i++)
    if (d[i] == -1) sol = 1;
  for (int i = 0; i < int(m); i++) {
    scanf("%d %d", &u, &v);
    u--, v--;
    adj[u].push_back(make_pair(v, i));
    adj[v].push_back(make_pair(u, i));
    in[u]++, in[v]++;
  }
  for (int i = 0; i < int(n); i++) {
    if (d[i] == -1) continue;
    if ((in[i] & 1) && d[i]) continue;
    if (!(in[i] & 1) && !d[i]) continue;
    has[i] = 1;
    problem++;
  }
  if (!sol && problem & 1) {
    puts("-1");
    return 0;
  }
  if (problem & 1) {
    for (int i = 0; i < int(n); i++) {
      if (d[i] == -1) {
        cur_id++;
        solve(i, i);
        has[i] = 0;
        break;
      }
    }
  }
  for (int i = 0; i < int(n); i++) {
    if (has[i]) {
      cur_id++;
      solve(i, i);
    }
  }
  int ans = 0;
  for (int i = 0; i < int(m); i++)
    if (!leave[i]) ans++;
  printf("%d\n", ans);
  for (int i = 0; i < int(m); i++)
    if (!leave[i]) printf("%d\n", i + 1);
  return 0;
}
