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 maxn = 1e6 + 7;
int n, m, d[maxn];
vector<pair<int, int> > g[maxn];
bool used[maxn];
pair<int, int> pred[maxn];
bool ans[maxn];
void dfs(int u) {
  used[u] = 1;
  for (int i = 0; i < g[u].size(); ++i) {
    pair<int, int> to = g[u][i];
    if (!used[to.first]) {
      pred[to.first] = {u, to.second};
      dfs(to.first);
    }
  }
  if (d[u]) {
    ans[pred[u].second] = 1;
    d[pred[u].first] = 1 - d[pred[u].first];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> d[i];
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i)
    if (d[i] != -1) cnt = (cnt + d[i]) % 2;
  for (int i = 0; i < n; ++i) {
    if (cnt % 2 && d[i] == -1)
      d[i] = 1, cnt--;
    else if (d[i] == -1)
      d[i] = 0;
  }
  cnt = 0;
  for (int i = 0; i < n; ++i) cnt = (cnt + d[i]);
  if (cnt % 2) return cout << "-1 \n", 0;
  dfs(0);
  int res = 0;
  for (int i = 0; i < m; ++i)
    if (ans[i]) ++res;
  cout << res << "\n";
  for (int i = 0; i < m; ++i)
    if (ans[i]) cout << i + 1 << " ";
  return 0;
}
