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 = 3e5 + 15;
const int mod = 1e9 + 7;
const int inf = 1e9 + 3;
int n, m;
int val[maxn];
int par[maxn];
int cnt[maxn];
int sz[maxn];
pair<int, int> edge[maxn];
vector<int> ans;
pair<int, int> his[maxn];
int hv[maxn];
bool mark[maxn];
int get(int x) {
  if (par[x] == x) return x;
  return get(par[x]);
}
void merg(int a, int b, int i) {
  a = get(a);
  b = get(b);
  if (a == b) {
    mark[i] = true;
    return;
  }
  if (sz[a] < sz[b]) swap(a, b);
  his[i] = pair<int, int>(a, b);
  sz[a] += sz[b];
  hv[i] = val[a];
  if (val[b] == -1) val[a] = -1;
  if (val[a] != -1) val[a] = val[a] ^ val[b];
  par[b] = a;
}
void add(int a) {
  cnt[a]++;
  if (par[a] == a) return;
  add(par[a]);
}
void unmerg(int a, int b, int i) {
  if (mark[i]) return;
  int u, v;
  v = his[i].first;
  u = his[i].second;
  sz[v] -= sz[u];
  cnt[v] -= cnt[u];
  val[v] = hv[i];
  par[u] = u;
  if (val[u] != -1 && val[u] != cnt[u] % 2) {
    add(a);
    add(b);
    ans.push_back(i);
    return;
  }
  if (val[v] != -1 && val[v] != cnt[u] % 2) {
    add(a);
    add(b);
    ans.push_back(i);
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> val[i];
    par[i] = i;
    sz[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    u--;
    v--;
    edge[i] = pair<int, int>(u, v);
    merg(u, v, i);
  }
  if (val[get(0)] == 1) return puts("-1"), 0;
  for (int i = m - 1; i >= 0; i--) unmerg(edge[i].first, edge[i].second, i);
  cout << ans.size() << endl;
  for (int w : ans) cout << w + 1 << ' ';
  cout << endl;
}
