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 long long SIZE = 1e5 * 3 + 10;
vector<long long> vec, any, curr;
vector<vector<long long>> graph;
map<pair<long long, long long>, long long> ch;
map<pair<long long, long long>, long long> us;
bool used[SIZE];
long long dfs(int v, int par = -1) {
  used[v] = 1;
  long long cnt = 0;
  for (auto to : graph[v]) {
    if (!used[to]) {
      long long q = dfs(to);
      if (q) {
        us[{v, to}] = 1;
        cnt ^= 1;
      }
    }
  }
  if (vec[v] == 1) return (cnt ^ 1);
}
vector<long long> edges;
long long ans(int v) {
  used[v] = 1;
  long long cnt = 0;
  for (auto to : graph[v]) {
    if (!used[to]) {
      long long q = ans(to);
      if (vec[to] != -1 && q != vec[to]) {
        edges.push_back(ch[{v, to}]);
        cnt ^= 1;
      }
    }
  }
  return cnt;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  long long n, m;
  cin >> n >> m;
  curr.resize(n);
  vec.resize(n);
  long long c = 0;
  long long s = 0;
  for (int i = 0; i < n; i++) {
    long long dif;
    cin >> dif;
    vec[i] = dif;
    if (dif == 1) s++;
  }
  graph.resize(n);
  for (int i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    graph[u].push_back(v);
    graph[v].push_back(u);
    ch[{u, v}] = i;
    ch[{v, u}] = i;
  }
  for (int i = 0; i < n; i++) {
    if (vec[i] == -1) {
      if (s % 2 == 1) {
        vec[i] = 1;
        s++;
      } else {
        vec[i] = 0;
      }
    }
  }
  if (s % 2 != 0) {
    cout << "-1";
    return 0;
  }
  dfs(0);
  set<long long> ans;
  for (auto cur : us) {
    ans.insert(ch[cur.first] + 1);
  }
  cout << ans.size() << "\n";
  for (auto cur : ans) {
    cout << cur << "\n";
  }
  return 0;
}
