#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{ ";
  for (const T& t : v) os << t << ", ";
  return os << "}";
}
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& pp) {
  return os << "{ " << pp.first << ", " << pp.second << " }";
}
struct edge {
  long long v;
  long long id;
};
vector<bool> vis;
vector<vector<edge>> adj;
vector<long long> ans;
vector<long long> sz;
vector<long long> tp;
void dfs(long long u) {
  vis[u] = true;
  sz[u] = (tp[u] == 1);
  for (edge e : adj[u]) {
    if (!vis[e.v]) {
      dfs(e.v);
      sz[u] += sz[e.v];
      if (sz[e.v] % 2 == 1) {
        ans.push_back(e.id);
      }
    }
  }
}
signed main() {
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  vis.assign(n, false);
  adj.resize(n);
  sz.resize(n);
  tp.resize(n);
  long long cnt[3] = {0};
  for (long long i = 0; i < n; ++i) {
    cin >> tp[i];
    cnt[tp[i] + 1]++;
  }
  for (long long i = 0; i < m; ++i) {
    long long x, y;
    cin >> x >> y;
    --x;
    --y;
    adj[x].push_back(edge({y, i + 1}));
    adj[y].push_back(edge({x, i + 1}));
  }
  if (cnt[2] % 2 == 1 && cnt[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (cnt[2] % 2 == 1) {
    for (long long i = 0; i < n; ++i) {
      if (tp[i] == -1) {
        tp[i] = 1;
        break;
      }
    }
  }
  for (long long i = 0; i < n; ++i) {
    if (!vis[i]) {
      dfs(i);
    }
  }
  cout << ans.size() << "\n";
  for (long long i : ans) {
    cout << i << "\n";
  }
  return 0;
}
