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 const MAXN = 3e5 + 8;
int const delta = 1000000007;
set<int> edges[MAXN];
int a[MAXN];
int mark[MAXN];
int dp[MAXN];
pair<int, int> e[MAXN];
set<int> ans;
void dfs(int v) {
  mark[v] = 1;
  int temp = 0;
  while (edges[v].size()) {
    int t = *edges[v].begin();
    edges[v].erase(t);
    int u = e[t].first;
    if (u == v) u = e[t].second;
    if (mark[u]) continue;
    dfs(u);
    if (dp[u]) {
      temp++;
      ans.insert(t);
    }
  }
  if (temp % 2 != a[v]) {
    dp[v] = 1;
  }
}
int main() {
  std::ios::sync_with_stdio(0);
  ;
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int u = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1) u++;
  }
  if (u % 2) {
    for (int i = 1; i <= n; i++) {
      if (a[i] != -1) continue;
      if (u % 2)
        a[i] = ((++u) % 2);
      else
        a[i] = 0;
    }
  } else {
    for (int i = 1; i <= n; i++) {
      if (a[i] == -1) a[i] = 0;
    }
  }
  int f, s;
  for (int i = 0; i < m; i++) {
    cin >> f >> s;
    edges[f].insert(i);
    edges[s].insert(i);
    e[i] = make_pair(f, s);
  }
  if (u % 2) return cout << -1, 0;
  dfs(1);
  cout << ans.size() << endl;
  for (set<int>::iterator i = ans.begin(); i != ans.end(); i++)
    cout << (*i) + 1 << endl;
  return 0;
}
