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 long long int N = 3e5 + 5, inf = -1e12;
long long int sum[N];
long long int root(long long int ary[], long long int i) {
  while (ary[i] != i) {
    ary[i] = ary[ary[i]];
    i = ary[i];
  }
  return i;
}
long long int un(long long int ary[], long long int a, long long int b) {
  long long int rA = root(ary, a);
  long long int rB = root(ary, b);
  if (rA == rB) return 0;
  if (sum[rA] > sum[rB]) {
    ary[rB] = rA;
    sum[rA] += sum[rB];
  } else {
    ary[rA] = rB;
    sum[rB] += sum[rA];
  }
  return 1;
}
map<pair<long long int, long long int>, long long int> M;
vector<long long int> G[N];
long long int vis[N];
long long int ary[N], val[N], par[N];
long long int dfs(long long int a, long long int p) {
  long long int c = 0;
  for (long long int i = 0; i < G[a].size(); ++i) {
    long long int x = G[a][i];
    if (x != p) {
      par[x] = a;
      c += dfs(x, a);
    }
  }
  c %= 2;
  if ((val[a] == 0 & c == 0) || (val[a] == 1 && c == 1)) {
    c = 0;
    if (par[a] == 0) return 0;
    if (M.count(make_pair(a, par[a]))) {
      M[make_pair(a, par[a])] = -1;
    } else {
      M[make_pair(par[a], a)] = -1;
    }
  } else if (val[a] != -1) {
    if (par[a] == 0) {
      c = -1;
    } else {
      c = 1;
    }
  }
  return c;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  vector<pair<long long int, long long int> > ord;
  for (long long int i = 1; i < n + 1; ++i) {
    ary[i] = i;
    sum[i] = 1;
    cin >> val[i];
    ord.push_back(make_pair(val[i], i));
  }
  sort(ord.begin(), ord.end());
  vector<long long int> v;
  for (long long int i = 0; i < m; ++i) {
    long long int a, b;
    cin >> a >> b;
    if (un(ary, a, b) != 0) {
      G[a].push_back(b);
      G[b].push_back(a);
      M[make_pair(a, b)] = i + 1;
    }
  }
  vector<long long int> ans;
  long long int f = 0;
  long long int c = dfs(ord[0].second, 0);
  if (c == -1) {
    f = 1;
  }
  if (f == 1) {
    cout << -1 << "\n";
  } else {
    vector<long long int> ans;
    for (auto it = M.begin(); it != M.end(); it++) {
      if ((*it).second != -1) ans.push_back((*it).second);
    }
    cout << ans.size() << "\n";
    sort(ans.begin(), ans.end());
    for (long long int i = 0; i < ans.size(); ++i) {
      cout << ans[i] << "\n";
    }
  }
  return 0;
}
