#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3 * 100 * 1000 + 4;
int n, m;
vector<pair<int, int> > adj[MAXN];
bool mark[MAXN];
int d[MAXN], o[MAXN];
int ans = 0;
bool vis[MAXN];
void dfs(int u) {
  vis[u] = true;
  if (d[u] == 1) o[u]++;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i].first;
    if (!vis[v]) {
      dfs(v);
      o[u] += o[v];
      if (o[v] % 2) {
        mark[adj[u][i].second] = true;
        ans++;
      }
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> d[i];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> v >> u;
    v--, u--;
    adj[v].push_back({u, i});
    adj[u].push_back({v, i});
  }
  int onee = 0;
  int mm = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == 1) onee++;
    if (d[i] == -1) mm++;
  }
  if (onee % 2 == 1) {
    if (mm == 0) {
      cout << -1 << endl;
      return 0;
    } else {
      for (int i = 0; i < n; i++) {
        if (d[i] == -1) {
          d[i] = 1;
          break;
        }
      }
    }
  }
  dfs(0);
  cout << ans << endl;
  for (int i = 0; i < m; i++) {
    if (mark[i]) {
      cout << (i + 1) << " ";
    }
  }
  cout << endl;
  return 0;
}
