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 inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);
const double eps = (double)1e-9;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 300500;
bool ok;
vector<int> ans;
vector<pair<int, int> > g[N];
int n, m, sum, a[N], p[N], sz[N], dp[N];
int get(int v) { return p[v] = (v == p[v] ? v : get(p[v])); }
inline void unite(int x, int y) {
  x = get(x);
  y = get(y);
  if (sz[x] < sz[y]) {
    p[x] = y;
    sz[y] += sz[x];
  } else {
    p[y] = x;
    sz[x] += sz[y];
  }
}
void dfs(int v, int pr = -1) {
  dp[v] = a[v];
  for (auto i : g[v]) {
    int to = i.first;
    if (to == pr) continue;
    dfs(to, v);
    dp[v] += dp[to];
    dp[v] &= 1;
  }
  int last;
  if (a[v] & 1)
    last = -2;
  else
    last = -1;
  for (auto i : g[v]) {
    int to = i.first;
    if (to == pr) continue;
    if (dp[to] & 1) {
      if (last == -2) {
        ans.push_back(i.second);
        last = -1;
        continue;
      }
      if (last != -1) {
        ans.push_back(last);
        ans.push_back(i.second);
        last = -1;
      } else
        last = i.second;
    }
  }
}
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    p[i] = i;
    sz[i] = 1;
    cin >> a[i];
    if (a[i] == -1)
      ok = 1;
    else {
      sum += a[i];
      sum &= 1;
    }
  }
  if ((sum & 1) && !ok) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    if (get(x) != get(y)) {
      unite(x, y);
      g[x].push_back({y, i});
      g[y].push_back({x, i});
    }
  }
  if (sum & 1) {
    for (int i = 1; i <= n; i++) {
      if (a[i] == -1) {
        a[i] = 1;
        for (int j = i + 1; j <= n; j++)
          if (a[i] == -1) a[i] = 0;
        break;
      }
    }
  } else
    for (int i = 1; i <= n; i++)
      if (a[i] == -1) a[i] = 0;
  dfs(1);
  cout << (int)ans.size() << endl;
  for (auto i : ans) cout << i << " ";
  return 0;
}
