#include <bits/stdc++.h>
using namespace std;
bool ans[300000];
int d[300000];
vector<pair<int, int> > g[300000];
bool used[300000];
bool dfs(int x) {
  used[x] = 1;
  bool ret = 0;
  for (int i = 0; i < g[x].size(); ++i) {
    if (!used[g[x][i].first]) {
      if (dfs(g[x][i].first)) {
        ret ^= 1;
        ans[g[x][i].second] = 1;
      }
    }
  }
  if (d[x] == 1) ret ^= 1;
  return ret;
}
int main() {
  int n, m;
  cin >> n >> m;
  int cnt = 0;
  int index = 0;
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
    if (d[i] == 1) {
      if (cnt == 0) index = i;
      cnt++;
    } else if (d[i] == -1) {
      index = i;
      cnt = n * 2;
    }
  }
  if (cnt < 2 * n && cnt % 2) {
    cout << -1 << endl;
    return 0;
  }
  int u, v;
  for (int i = 0; i < m; ++i) {
    cin >> u >> v;
    g[--u].push_back({--v, i});
    g[v].push_back({u, i});
  }
  dfs(index);
  cnt = 0;
  for (int i = 0; i < m; ++i) {
    cnt += ans[i];
  }
  cout << cnt << endl;
  for (int i = 0; i < m; ++i) {
    if (ans[i]) cout << i + 1 << " ";
  }
  return 0;
}
