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;
long long int x, y;
long long int gcd(long long int a, long long int b) {
  if (a == 0) {
    x = 0, y = 1;
    return b;
  }
  long long int gc = gcd(b % a, a);
  long long int temp;
  temp = x;
  x = y - (b / a) * temp;
  y = temp;
  return gc;
}
long long int pow(long long int a, long long int x, long long int m) {
  long long int ans = 1, k = 1;
  while (k <= x) {
    if (x % k) ans = ((ans * a) % m);
    k <<= 1;
    a *= a;
    a %= m;
  }
  return ans;
}
int a[300005];
vector<pair<int, int> > tree[300005];
int visited[300005];
int mark[300005];
map<pair<int, int>, int> edges;
int dfs(int node) {
  if (visited[node]) return 0;
  visited[node] = 1;
  int satisfied;
  satisfied = a[node - 1] ^ (tree[node].size() % 2);
  if (a[node - 1] == -1) satisfied = 0;
  for (int i = 0; i < tree[node].size(); i++) {
    if (!visited[tree[node][i].first]) {
      int temp = dfs(tree[node][i].first);
      if (temp) {
        mark[tree[node][i].second] = -1;
      }
      satisfied ^= temp;
    }
  }
  return satisfied;
}
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  int u, v;
  for (i = 0; i < m; i++) {
    cin >> u >> v;
    if (edges[{u, v}] != 1) {
      edges[{u, v}] = 1;
      edges[{v, u}] = 1;
      tree[u].push_back({v, i + 1});
      tree[v].push_back({u, i + 1});
    }
  }
  for (i = 1; i <= n; i++) {
    if (a[i - 1] == -1 && !visited[i]) {
      dfs(i);
    }
  }
  for (i = 1; i <= n; i++) {
    if (!visited[i] && dfs(i)) {
      cout << -1;
      return 0;
    }
  }
  vector<int> tem;
  for (i = 1; i <= m; i++) {
    if (mark[i] != -1) {
      tem.push_back(i);
    }
  }
  cout << tem.size() << endl;
  for (i = 0; i < tem.size(); i++) {
    cout << tem[i] << " ";
  }
}
