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;
inline void Max(int &x, int t) {
  if (t > x) {
    x = t;
  }
}
inline void Min(int &x, int t) {
  if (t < x) {
    x = t;
  }
}
const int maxn = 300000 + 9;
int N, M, d[maxn], fa[maxn];
vector<pair<int, int> > g[maxn];
vector<int> ans;
int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }
bool chk() {
  int cnt = 0;
  bool F = true;
  for (int i = 0; i < N; i++) {
    if (d[i] == -1) {
      F = false;
    } else {
      cnt ^= (d[i] & 1);
    }
  }
  if (!F) {
    for (int i = 0; i < N; i++)
      if (d[i] == -1) {
        d[i] = ((cnt & 1) ? 1 : 0);
        cnt ^= d[i];
      }
    return false;
  }
  return cnt;
}
bool dfs(int x, int p) {
  for (auto e : g[x])
    if (e.first != p) {
      if (dfs(e.first, x)) {
        ans.push_back(e.second);
        d[x] ^= 1;
      }
    }
  return d[x];
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    scanf("%d", d + i);
    fa[i] = i;
  }
  if (chk()) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= M; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    int _u = Find(--u), _v = Find(--v);
    if (_u != _v) {
      g[u].push_back(make_pair(v, i));
      g[v].push_back(make_pair(u, i));
      fa[_u] = _v;
    }
  }
  dfs(0, -1);
  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (auto e : ans) {
    printf("%d ", e);
  }
  return 0;
}
