#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, m, d[N];
pair<int, int> edge[N];
vector<int> nb[N];
bool keep[N];
int adj(int u, int id) {
  return (edge[id].first == u ? edge[id].second : edge[id].first);
}
bool bad[N], vis[N];
vector<int> path;
bool DFS(int v) {
  vis[v] = true;
  bool flips = 0;
  for (int id : nb[v]) {
    int u = adj(v, id);
    if (vis[u]) continue;
    path.push_back(id);
    flips ^= DFS(u);
    path.pop_back();
  }
  if (!path.empty()) {
    if (bad[v]) flips ^= 1;
    keep[path.back()] ^= flips;
  }
  return flips;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> d[i];
  for (int i = 1; i <= m; i++) {
    cin >> edge[i].first >> edge[i].second;
    nb[edge[i].first].push_back(i);
    nb[edge[i].second].push_back(i);
    keep[i] = true;
  }
  int root = -1, baddies = 0;
  for (int i = 1; i <= n; i++) {
    if (d[i] == -1)
      root = i;
    else if (d[i] != (int)nb[i].size() % 2) {
      bad[i] = true;
      baddies++;
    }
  }
  if (root == -1 && (baddies & 1)) {
    cout << -1 << '\n';
    return 0;
  }
  if (root == -1) root = 1;
  DFS(root);
  vector<int> ans;
  for (int i = 1; i <= m; i++)
    if (keep[i]) ans.push_back(i);
  cout << ans.size() << '\n';
  for (int x : ans) cout << x << ' ';
  cout << '\n';
  return 0;
}
