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 long long N = 3e5 + 5;
struct edge {
  long long id, v;
};
vector<long long> d;
vector<edge> adj[N];
vector<bool> used;
bitset<N> vis;
bool cur = false;
void dfs(long long u) {
  if (vis[u]) return;
  vis[u] = true;
  if (d[u]) cur = !cur;
  for (edge e : adj[u]) {
    used[e.id] = cur ^ used[e.id];
    dfs(e.v);
    used[e.id] = cur ^ used[e.id];
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  d = vector<long long>(n);
  used = vector<bool>(m, false);
  long long numOdd = 0, numFree = 0;
  for (long long i = 0; i < (long long)(n); i++) {
    cin >> d[i];
    if (d[i] == 1) numOdd++;
    if (d[i] == -1) numFree++;
  }
  for (long long i = 0; i < (long long)(m); i++) {
    long long a, b;
    cin >> a >> b;
    a--, b--;
    adj[a].push_back({i, b});
    adj[b].push_back({i, a});
  }
  if (numOdd % 2 && !numFree) {
    cout << "-1\n";
  } else {
    if (numOdd % 2) {
      for (long long i = 0; i < (long long)(n); i++) {
        if (d[i] == -1) {
          d[i] = 1;
          break;
        }
      }
    }
    for (long long i = 0; i < (long long)(n); i++)
      if (d[i] == -1) d[i] = 0;
    dfs(0);
    long long numUsed = 0;
    for (long long i = 0; i < (long long)(m); i++)
      if (used[i]) numUsed++;
    cout << numUsed << "\n";
    for (long long i = 0; i < (long long)(m); i++)
      if (used[i]) cout << i + 1 << "\n";
  }
}
