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 arr[300005];
vector<pair<int, int> > G[300005];
bool vis[300005];
vector<int> ans;
bool dfs1(int u) {
  vis[u] = true;
  for (pair<int, int> e : G[u]) {
    int v = e.first, idx = e.second;
    if (!vis[v] && arr[v] != -1) {
      if (dfs1(v)) {
        if (arr[u] != -1) arr[u] ^= 1;
        ans.emplace_back(idx);
      }
    }
  }
  return arr[u] == 1;
}
bool dfs2(int u) {
  vis[u] = true;
  for (pair<int, int> e : G[u]) {
    int v = e.first, idx = e.second;
    if (!vis[v]) {
      if (dfs2(v)) {
        arr[u] ^= 1;
        ans.emplace_back(idx);
      }
    }
  }
  return arr[u] == 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> idxs;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (arr[i] == -1) idxs.emplace_back(i);
  }
  for (int i = 1, u, v; i <= m; i++) {
    cin >> u >> v;
    G[u].emplace_back(pair<int, int>{v, i});
    G[v].emplace_back(pair<int, int>{u, i});
  }
  for (int root : idxs) dfs1(root);
  for (int i = 1; i <= n; i++)
    if (!vis[i] && dfs2(i)) {
      cout << -1 << '\n';
      return 0;
    }
  cout << (int)ans.size() << '\n';
  for (int i = 0; i < (int)ans.size(); i++) {
    if (i != 0) cout << " ";
    cout << ans[i];
  }
  cout << '\n';
  return 0;
}
