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 maxN = 3 * 1e5 + 190;
int n, d[maxN], m, p[maxN], dd[maxN];
vector<pair<int, int> > adj[maxN];
vector<int> ans;
void dfs(int u) {
  dd[u] = 1;
  for (__typeof((adj[u]).begin()) it = (adj[u]).begin(); it != (adj[u]).end();
       ++it) {
    int v = it->first;
    if (!dd[v]) {
      dfs(v);
      p[v] = u;
    }
  }
}
void travel(int u) {
  for (__typeof((adj[u]).begin()) it = (adj[u]).begin(); it != (adj[u]).end();
       ++it) {
    int v = it->first;
    if (p[v] == u) {
      travel(v);
      int id = it->second;
      if (d[v] == 1) {
        d[u] = 1 - d[u];
        ans.push_back(id);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> d[i + 1];
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(pair<int, int>(b, i + 1));
    adj[b].push_back(pair<int, int>(a, i + 1));
  }
  pair<int, int> check = pair<int, int>(0, 0);
  for (int i = 1; i <= n; ++i) {
    check.first += d[i];
    check.second = (d[i] == -1);
  }
  if (check.second == 0 && (check.first & 1)) {
    cout << -1;
    return 0;
  }
  p[1] = 1;
  dfs(1);
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    if (d[i] == -1) {
      if (sum & 1)
        d[i] = 1;
      else
        d[i] = 0;
    }
    sum += d[i];
  }
  travel(1);
  cout << ans.size() << '\n';
  for (__typeof((ans).begin()) it = (ans).begin(); it != (ans).end(); ++it)
    cout << *it << '\n';
  return 0;
}
