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 = 300001;
vector<int> g[maxn];
int n, m;
int d[maxn];
int D[maxn];
pair<int, int> E[maxn];
map<pair<int, int>, int> tree;
void enter() {
  cin >> n >> m;
  for (int i = (1), _b = (n + 1); i < _b; ++i) cin >> d[i];
  for (int i = (1), _b = (m + 1); i < _b; ++i) {
    int u, v;
    cin >> u >> v;
    E[i] = pair<int, int>(u, v);
    D[u]++;
    D[v]++;
    if (tree[pair<int, int>(min(u, v), max(u, v))] == 0) {
      tree[pair<int, int>(min(u, v), max(u, v))] = i;
      g[u].push_back(v);
      g[v].push_back(u);
    }
  }
}
bool _d[maxn];
int h[maxn];
int p[maxn][19];
vector<int> _g[maxn];
void dfs(int u) {
  _d[u] = true;
  for (auto i : g[u]) {
    if (!_d[i]) {
      _g[i].push_back(u);
      _g[u].push_back(i);
      dfs(i);
    }
  }
}
void dfs2(int u, int anc, int hh) {
  h[u] = hh;
  p[u][0] = anc;
  for (int i = (1), _b = (19); i < _b; ++i) {
    p[u][i] = p[p[u][i - 1]][i - 1];
  }
  for (auto i : _g[u])
    if (i != anc) dfs2(i, u, hh + 1);
}
int lca(int u, int v) {
  if (h[u] < h[v]) swap(u, v);
  for (int i = 18; i >= 0; --i) {
    if (h[p[u][i]] >= h[v]) u = p[u][i];
  }
  if (u == v) return u;
  for (int i = 18; i >= 0; --i)
    if (p[u][i] != p[v][i]) {
      u = p[u][i];
      v = p[v][i];
    }
  return p[u][0];
}
int las;
int f[maxn];
set<int> edge;
void del(int u, int v) {
  int anc = lca(u, v);
  while (u != anc) {
    edge.insert(tree[pair<int, int>(min(u, p[u][0]), max(u, p[u][0]))]);
    u = p[u][0];
  }
  while (v != anc) {
    edge.insert(tree[pair<int, int>(min(v, p[v][0]), max(v, p[v][0]))]);
    v = p[v][0];
  }
}
void xoacanh(int u, int anc) {
  vector<int> p;
  for (auto i : _g[u])
    if (i != anc) {
      xoacanh(i, u);
      if (f[i] != 0) p.push_back(f[i]);
    }
  if (p.size() == 2) {
    del(p.front(), p.back());
  } else if (p.size() == 1) {
    if (_d[u]) {
      del(u, p.front());
      f[u] = 0;
    } else
      f[u] = p.front();
  } else {
    if (_d[u]) f[u] = u;
  }
}
void solve() {
  dfs(1);
  dfs2(1, 0, 1);
  memset(_d, false, sizeof _d);
  int cnt = 0;
  for (int i = (1), _b = (n + 1); i < _b; ++i) {
    if (d[i] == -1)
      las = i;
    else if (d[i] != D[i] % 2) {
      _d[i] = true;
      ++cnt;
    }
  }
  if (cnt % 2 != 0 && las == 0) {
    cout << "-1";
    return;
  }
  if (cnt % 2 != 0) {
    _d[las] = true;
  }
  xoacanh(1, 0);
  vector<int> cal;
  for (int i = (1), _b = (m + 1); i < _b; ++i)
    if (edge.find(i) == edge.end()) cal.push_back(i);
  cout << cal.size() << "\n";
  for (auto i : cal) cout << i << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  enter();
  solve();
}
