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 mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 3e5 + 5;
int n, m, d[N], dp[N][2];
vector<int> g[N];
vector<int> tree[N];
bool vis[N], deg[N];
bool isAnc[N];
map<pair<int, int>, int> id;
vector<int> edges;
void dfs(int u, int p) {
  vis[u] = 1;
  isAnc[u] = 1;
  if (p != -1) tree[p].push_back(u);
  for (auto v : g[u])
    if (v != p) {
      if (!vis[v]) {
        dfs(v, u);
      } else {
        if (!isAnc[v]) {
          edges.push_back(id[pair<int, int>(u, v)]);
          deg[v] ^= 1;
          deg[u] ^= 1;
        }
      }
    }
  isAnc[u] = 0;
}
struct PrvState {
  int v = -1;
  bool picked = 0;
  bool vState = 0;
  PrvState(int v = -1, bool picked = 0, bool vState = 0)
      : v(v), picked(picked), vState(vState){};
};
vector<PrvState> choices[N][2];
void dfs2(int u, int p) {
  dp[u][deg[u]] = 1, dp[u][deg[u] ^ 1] = 0;
  vector<PrvState> prv[2];
  prv[0].resize(tree[u].size());
  prv[1].resize(tree[u].size());
  int cur = 0;
  for (auto v : tree[u]) {
    dfs2(v, u);
    int og0 = dp[u][0], og1 = dp[u][1];
    dp[u][0] = dp[u][1] = 0;
    bool prv0 = dp[u][0], prv1 = dp[u][1];
    if (d[v] == -1) {
      dp[u][0] = max(dp[u][0], og1 & (dp[v][0] | dp[v][1]));
      dp[u][1] = max(dp[u][1], og0 & (dp[v][0] | dp[v][1]));
    } else {
      int revDeg = (d[v] ^ 1);
      dp[u][0] = max(dp[u][0], og1 & dp[v][revDeg]);
      dp[u][1] = max(dp[u][1], og0 & dp[v][revDeg]);
    }
    int vState = 0;
    if (d[v] == -1) {
      if (dp[v][1]) vState = 1;
    } else {
      vState = (d[v] ^ 1);
    }
    if (dp[u][0] && !prv0) prv[0][cur] = PrvState(v, 1, vState);
    if (dp[u][1] && !prv1) prv[1][cur] = PrvState(v, 1, vState);
    prv0 = dp[u][0], prv1 = dp[u][1];
    if (d[v] == -1) {
      dp[u][0] = max(dp[u][0], og0 & (dp[v][0] | dp[v][1]));
      dp[u][1] = max(dp[u][1], og1 & (dp[v][0] | dp[v][1]));
    } else {
      dp[u][0] = max(dp[u][0], og0 & dp[v][d[v]]);
      dp[u][1] = max(dp[u][1], og1 & dp[v][d[v]]);
    }
    vState = 0;
    if (d[v] == -1) {
      if (dp[v][1]) vState = 1;
    } else {
      vState = d[v];
    }
    if (dp[u][0] && !prv0) prv[0][cur] = PrvState(v, 0, vState);
    if (dp[u][1] && !prv1) prv[1][cur] = PrvState(v, 0, vState);
    cur++;
  }
  for (int j = 0; j < 2; j++)
    if (dp[u][j]) {
      int cur = j;
      for (int i = tree[u].size() - 1; i >= 0; i--) {
        PrvState lol = prv[cur][i];
        assert(lol.v != -1);
        choices[u][j].push_back(lol);
        cur ^= lol.picked;
      }
    }
}
void findAns(int u, bool state) {
  assert(u != -1);
  for (auto j : choices[u][state]) {
    findAns(j.v, j.vState);
    if (j.picked) edges.push_back(id[pair<int, int>(u, j.v)]);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> d[i];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    if (id.count(pair<int, int>(u, v))) continue;
    g[u].push_back(v), g[v].push_back(u);
    id[pair<int, int>(u, v)] = id[pair<int, int>(v, u)] = i;
  }
  dfs(0, -1);
  dfs2(0, -1);
  bool ans = (dp[0][0] | dp[0][1]);
  if (d[0] == 0)
    ans = dp[0][0];
  else if (d[0] == 1)
    ans = dp[0][1];
  if (!ans)
    cout << "-1\n";
  else {
    bool neededState = 0;
    if (d[0] == 1)
      neededState = 1;
    else if (d[0] == 0)
      neededState = 0;
    else {
      if (dp[0][0]) neededState = 0;
      if (dp[0][1]) neededState = 1;
    }
    findAns(0, neededState);
    sort(edges.begin(), edges.end());
    cout << edges.size() << "\n";
    for (auto i : edges) cout << i + 1 << "\n";
  }
  return 0;
}
