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;
using ll = long long;
const int MAXI = 300004;
int n, m;
int d[MAXI];
int countiT[MAXI], countiF[MAXI];
vector<vector<pair<int, int> > > g;
char used[MAXI];
bool changeBalance;
void input() {
  cin >> n >> m;
  g.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    countiF[i] = 0;
    countiT[i] = 0;
    cin >> d[i];
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    used[i] = 0;
    cin >> u >> v;
    g[u].push_back(make_pair(v, i));
    g[v].push_back(make_pair(u, i));
    countiT[u]++;
    countiT[v]++;
  }
}
bool balance(int v) { return countiF[v] % 2 == d[v] || d[v] == -1; }
void counting(int v) {
  if (balance(v)) return;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first;
    int toLink = g[v][i].second;
    if (!used[toLink] && !balance(to)) {
      used[toLink] = 1;
      countiF[v]++;
      countiF[to]++;
      changeBalance = 1;
      return;
    }
  }
  int toBest = 0;
  int toLinkBest = 0;
  int bestCounti = 0;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first;
    int toLink = g[v][i].second;
    if (!used[toLink]) {
      if (!toBest) {
        toBest = to;
        toLinkBest = toLink;
        bestCounti = countiT[toBest] - countiF[toBest];
      } else {
        if (bestCounti < countiT[to] - countiF[to] ||
            (d[to] == -1 && d[toBest] != -1)) {
          toBest = to;
          toLinkBest = toLink;
          bestCounti = countiT[toBest] - countiF[toBest];
        }
      }
    }
  }
  if (toBest) {
    used[toLinkBest] = 1;
    countiF[v]++;
    countiF[toBest]++;
    changeBalance = 1;
  } else {
    cout << "-1" << endl;
    exit(0);
  }
}
int main() {
  input();
  changeBalance = 1;
  while (changeBalance) {
    changeBalance = 0;
    for (int i = 1; i <= n; i++) {
      counting(i);
    }
  }
  int k = 0;
  for (int i = 1; i <= m; i++) {
    if (used[i]) k++;
  }
  cout << k << endl;
  for (int i = 1; i <= m; i++) {
    if (used[i]) cout << i << endl;
  }
  return 0;
}
