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 MX = (1 << 20);
vector<pair<int, int> > v[MX];
int state[MX], deg[MX], shit = 0, dp[MX];
set<int> sol;
int n, m, vis[MX];
void dfs(int x, int p) {
  vis[x] = 1;
  if (state[x] != -1) dp[x] = state[x];
  for (auto pp : v[x]) {
    int nxt = pp.first;
    if (vis[nxt]) continue;
    dfs(nxt, x);
    if (dp[nxt]) {
      sol.insert(pp.second);
      ++dp[x];
    }
  }
  dp[x] %= 2;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int j = 1; j <= n; j++) scanf("%d", &state[j]);
  for (int j = 1; j <= m; j++) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (a == b) continue;
    v[a].push_back({b, j});
    v[b].push_back({a, j});
    deg[a] ^= 1;
    deg[b] ^= 1;
  }
  for (int j = 1; j <= n; j++) {
    if (state[j] != -1) {
      state[j] ^= deg[j];
      shit += state[j];
    }
  }
  if (shit) {
    bool ok = 0;
    for (int j = 1; j <= n; j++) {
      if (state[j] == -1) {
        dfs(j, -1);
        ok = 1;
        break;
      }
    }
    if (!ok) {
      puts("-1");
      return 0;
    }
  } else
    dfs(1, -1);
  vector<int> amr;
  for (int j = 1; j <= m; j++) {
    if (sol.count(j) == 0) amr.push_back(j);
  }
  cout << amr.size() << endl;
  for (auto pp : amr) printf("%d\n", pp);
}
