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 sz = 3e5 + 3, mod = 998244353;
long long t, n, m, k, q;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long Inv(long long a) { return power(a, mod - 2); }
vector<pair<long long, long long> > gr[sz];
long long v[sz];
long long vis[sz];
vector<long long> ans;
bool DFS(long long s, long long p) {
  vis[s] = 1;
  long long mask = 0;
  for (auto i : gr[s]) {
    if (i.first != p && vis[i.first] == 0) {
      bool ms = DFS(i.first, s);
      if (ms) ans.push_back(i.second);
      mask ^= ms;
    }
  }
  if (v[s] == -1) return 0;
  return (v[s] ^ mask);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  t = 1;
  while (t--) {
    cin >> n >> m;
    for (long long i = 1; i <= n; i++) cin >> v[i];
    for (long long i = 0; i < m; i++) {
      long long a, b;
      cin >> a >> b;
      gr[a].push_back({b, i + 1});
      gr[b].push_back({a, i + 1});
    }
    long long sr = 1;
    for (long long i = 1; i <= n; i++) {
      if (v[i] == -1) {
        sr = i;
        break;
      }
    }
    if (DFS(sr, sr)) {
      cout << -1 << "\n";
      return 0;
    }
    cout << ans.size() << "\n";
    for (auto i : ans) cout << i << "\n";
  }
  return 0;
}
