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;
const int N = 333333;
vector<pair<int, int> > graph[N];
int vis[N], d[N];
bool has[N];
int n, m;
int dfs(int u) {
  vis[u] = true;
  int cnt = 0;
  for (auto e : graph[u]) {
    if (!vis[e.first]) {
      if (dfs(e.first)) {
        has[e.second] = true;
        cnt++;
      }
    }
  }
  return cnt % 2 != d[u];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = (1); i <= (n); i++) {
    cin >> d[i];
  }
  for (int i = (1); i <= (m); i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(make_pair(v, i));
    graph[v].push_back(make_pair(u, i));
  }
  int cnt = 0;
  for (int i = (1); i <= (n); i++) {
    cnt += d[i] == 1;
  }
  for (int i = (1); i <= (n); i++) {
    if (d[i] == -1) {
      if (cnt & 1) {
        d[i] = 1;
        cnt++;
      } else {
        d[i] = 0;
      }
    }
  }
  if (cnt & 1) {
    cout << -1 << "\n";
    return 0;
  }
  dfs(1);
  vector<int> v;
  for (int i = (1); i <= (m); i++) {
    if (has[i]) {
      v.push_back(i);
    }
  }
  cout << (int)(v).size() << "\n";
  for (auto x : v) {
    cout << x << " ";
  }
  cout << "\n";
  return 0;
}
