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 D[300010];
vector<pair<int, int>> edges[300010];
int edge_states[300010];
bool used[300010];
void dfs1(int n) {
  used[n] = true;
  for (auto m : edges[n]) {
    if (used[m.first]) continue;
    edge_states[m.second] = 0;
    dfs1(m.first);
  }
}
int dfs2(int n, int p, int pe) {
  int cnt = D[n];
  for (auto m : edges[n]) {
    if (edge_states[m.second] == -1 || m.first == p) continue;
    cnt += dfs2(m.first, n, m.second);
  }
  if (cnt % 2 == 1) edge_states[pe] = 1;
  return cnt % 2;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> N >> M;
  for (int i = 0; i < (N); i++) cin >> D[i];
  for (int i = 0; i < (M); i++) {
    int a, b;
    cin >> a >> b;
    edges[a - 1].push_back(make_pair(b - 1, i));
    edges[b - 1].push_back(make_pair(a - 1, i));
  }
  int cnt1 = 0;
  int cnt_1 = 0;
  for (int i = 0; i < (N); i++)
    if (D[i] == 1)
      cnt1 += 1;
    else if (D[i] == -1)
      cnt_1 += 1;
  if (cnt1 % 2 == 1 && cnt_1 == 0) {
    cout << -1 << endl;
    return 0;
  } else if (cnt1 % 2 == 1 && cnt_1 > 0) {
    for (int i = 0; i < (N); i++)
      if (D[i] == -1) {
        D[i] = 1;
        break;
      }
  }
  for (int i = 0; i < (M); i++) edge_states[i] = -1;
  memset(used, 0, sizeof(used));
  dfs1(0);
  dfs2(0, -1, 0);
  int ans = 0;
  for (int i = 0; i < (M); i++)
    if (edge_states[i] == 1) ans += 1;
  if (ans == 0) {
    cout << ans << endl;
    return 0;
  }
  cout << ans << endl;
  for (int i = 0; i < (M); i++)
    if (edge_states[i] == 1) cout << i + 1 << "\n";
}
