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 mod = 1e9 + 7;
const int N = 5e5 + 10;
int d[N], mata[N];
vector<pair<int, int>> v[N], edge[N];
vector<int> ans;
int findmata(int s) {
  return mata[s] = ((s == mata[s]) ? s : findmata(mata[s]));
}
void dfs(int s) {
  for (auto it : edge[s]) {
    dfs(it.first);
    if (d[it.first] == 1) {
      ans.push_back(it.second);
      d[s] = 1 - d[s];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int odd = 0;
  for (int i = 1; i <= n; i++) mata[i] = i;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    if (d[i] != -1 && d[i] & 1) odd++;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back({b, i + 1});
    v[b].push_back({a, i + 1});
  }
  for (int i = 1; i <= n; i++) {
    if (d[i] == -1 && odd & 1) {
      d[i] = 1;
      odd++;
    } else if (d[i] == -1)
      d[i] = 0;
  }
  if (odd & 1) {
    puts("-1");
    return 0;
  }
  int root = -1;
  for (int i = 1; i <= n; i++) {
    int x = findmata(i);
    for (auto it : v[i]) {
      int y = findmata(it.first);
      if (x != y) {
        mata[y] = x;
        edge[i].push_back(it);
        if (root == -1) root = i;
      }
    }
  }
  dfs(root);
  cout << ans.size() << "\n";
  for (auto it : ans) cout << it << " ";
  cout << "\n";
  return 0;
}
