3 2
1 0 1
1 2
2 3
 10 10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
6 7
8 3
6 4
4 2
9 2
5 10
9 8
10 7
5 1
6 2

2
1
2
 0

#include <bits/stdc++.h>
using namespace std;
map<pair<long int, long int>, long int> ma;
int main() {
  deque<long int> dq;
  long int n, m, i, d[300005], u, v, cnt = 0, cur, tcnt;
  bool b[300005];
  set<long int> se[300005];
  vector<long int> ans;
  cin >> n >> m;
  tcnt = m;
  for (i = 1; i <= n; i++) {
    b[i] = 0;
    scanf("%ld", &d[i]);
    if (d[i] == 1) {
      cnt++;
      dq.push_back(i);
    }
  }
  for (i = 1; i <= m; i++) {
    scanf("%ld %ld", &u, &v);
    ma[make_pair(u, v)] = i;
    ma[make_pair(v, u)] = i;
    se[u].insert(v);
    se[v].insert(u);
  }
  set<long int>::iterator iter;
  bool fg = 0;
  long int lp = 0;
  while (cnt > 0 && !dq.empty()) {
    if (lp == dq.size()) {
      fg = 1;
      break;
    }
    while (!dq.empty()) {
      if ((b[dq.front()] || !d[dq.front()])) {
        dq.pop_front();
        lp = 0;
        cnt--;
      } else
        break;
    }
    if (dq.size() == 0) {
      break;
    }
    cur = dq.front();
    iter = se[cur].begin();
    if (iter == se[cur].end()) {
      dq.pop_front();
      dq.push_back(cur);
      lp++;
      continue;
    }
    lp = 0;
    long int itr = *iter;
    if (d[itr] == -1) {
      ans.push_back(ma[make_pair(cur, itr)]);
      se[cur].erase(itr);
      se[itr].erase(cur);
      d[cur] = 0;
      dq.pop_front();
      cnt--;
    } else if (d[itr] == 1) {
      ans.push_back(ma[make_pair(cur, itr)]);
      b[itr] = !b[itr];
      se[cur].erase(itr);
      se[itr].erase(cur);
      d[cur] = d[itr] = 0;
      dq.pop_front();
      cnt--;
    } else {
      ans.push_back(ma[make_pair(cur, itr)]);
      dq.push_back(itr);
      dq.pop_front();
      se[cur].erase(itr);
      d[itr] = 1;
      d[cur] = 0;
      se[itr].erase(cur);
    }
  }
  if (fg) {
    cout << "-1";
  } else {
    cout << ans.size() << endl;
    for (i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  }
  return 0;
}
