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;
int n, m;
int val[300000];
bool visited[300000];
bool inAnswer[300000];
vector<pair<int, int> > connections[300000];
bool dfs(int node) {
  visited[node] = true;
  if (val[node] <= 0) return true;
  for (const pair<int, int> edge : connections[node]) {
    if (visited[edge.first]) continue;
    if (val[edge.first] >= 0) val[edge.first] ^= 1;
    val[node] ^= 1;
    if (dfs(edge.first)) {
      inAnswer[edge.second] = !inAnswer[edge.second];
      return true;
    }
    val[node] ^= 1;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < (n); i++) cin >> val[i];
  for (int i = 0; i < (m); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    connections[a].push_back(make_pair(b, i));
    connections[b].push_back(make_pair(a, i));
  }
  for (int i = 0; i < (n); i++) {
    if (val[i] == 1) {
      memset(visited, 0, sizeof(visited));
      if (!dfs(i)) {
        cout << "-1\n";
        return 0;
      }
    }
  }
  int k = 0;
  for (int i = 0; i < (m); i++)
    if (inAnswer[i]) k++;
  cout << k << "\n";
  for (int i = 0; i < (m); i++)
    if (inAnswer[i]) cout << i + 1 << "\n";
  return 0;
}
