#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
vector<pair<int, int> > v[N];
bool vis[N];
int d[N];
set<int> se;
int dfs(int s) {
  if (vis[s]) return 1;
  vis[s] = 1;
  int degree = 0;
  for (int i = 0; i < v[s].size(); i++) {
    if (!dfs(v[s][i].first)) {
      degree++;
      se.insert(v[s][i].second);
    }
  }
  return (!(d[s] + 1) || degree % 2 == d[s]);
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, root = 1;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    if (!(d[i] + 1)) root = i;
  }
  int i = 0;
  while (m--) {
    i++;
    int x, y;
    cin >> x >> y;
    v[x].push_back({y, i});
    v[y].push_back({x, i});
  }
  if (!dfs(root)) return cout << -1, 0;
  cout << se.size() << endl;
  set<int>::iterator it = se.begin();
  while (it != se.end()) cout << (*it) << "\n", it++;
  return 0;
}
