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 double PI = 4 * atan(1);
int N, M;
vector<int> adj[300013];
int D[300013];
map<pair<int, int>, int> e_to_idx;
vector<int> ch[300013];
bool visited[300013];
vector<int> ans;
int dfs(int n, int p) {
  visited[n] = true;
  int deg = 0;
  for (int v : adj[n])
    if (!visited[v]) {
      int use = dfs(v, n);
      deg += use;
    }
  deg %= 2;
  if (deg != D[n]) {
    assert(n);
    ans.push_back(e_to_idx[{n, p}]);
    return 1;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  int degreeSum = 0;
  bool hasNeg = false;
  for (int i = 0; i < N; i++) {
    cin >> D[i];
    if (D[i] == -1) {
      hasNeg = true;
    } else {
      degreeSum += D[i];
    }
  }
  degreeSum %= 2;
  if (degreeSum % 2 == 1 && !hasNeg) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    if (D[i] == -1) {
      if (degreeSum) {
        degreeSum = 0;
        D[i] = 1;
      } else {
        D[i] = 0;
      }
    }
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    e_to_idx[{a, b}] = e_to_idx[{b, a}] = i + 1;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(0, -1);
  cout << ans.size() << endl;
  sort(ans.begin(), ans.end());
  for (int x : ans) {
    cout << x << '\n';
  }
  cout << flush;
  return 0;
}
