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, x, y, d[300100], cnt;
vector<int> v;
vector<pair<int, int> > graph[300100];
bool vis[300100];
int dfs(int u, int e) {
  vis[u] = 1;
  bool mask = d[u];
  for (int i = 0; i < graph[u].size(); i++) {
    int v = graph[u][i].first;
    int e = graph[u][i].second;
    if (vis[v]) continue;
    mask ^= dfs(v, e);
  }
  if (mask) v.push_back(e);
  return mask;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    if (d[i] == 1) cnt++;
  }
  for (int i = 1; i <= n; i++) {
    if (d[i] == -1) {
      if (cnt % 2 == 1)
        d[i] = 1;
      else
        d[i] = 0;
    }
  }
  if (cnt % 2 == 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    graph[x].push_back(make_pair(y, i));
    graph[y].push_back(make_pair(x, i));
  }
  dfs(1, -1);
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) cout << v[i] << endl;
  return 0;
}
