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 MAXN = 330000;
int d[MAXN];
vector<pair<int, int>> g[MAXN], p[MAXN][2];
int fa[MAXN];
bool vis[MAXN];
bool f[MAXN][2];
void dfs(int u) {
  vis[u] = 1;
  if (d[u] == -1)
    f[u][0] = f[u][1] = 1;
  else if (d[u] == 0)
    f[u][0] = 1, f[u][1] = 0;
  else
    f[u][0] = 0, f[u][1] = 1;
  int t = 0;
  for (auto e : g[u]) {
    int v = e.first;
    if (!vis[v]) {
      fa[v] = e.second;
      dfs(v);
      if (f[v][0] && f[v][1]) {
        p[u][0].push_back(make_pair(v, f[u][0] ^ 1));
        p[u][1].push_back(make_pair(v, f[u][1] ^ 1));
        f[u][0] = f[u][1] = 1;
      } else if (f[v][1]) {
        swap(f[u][0], f[u][1]);
        p[u][0].push_back(make_pair(v, 1));
        p[u][1].push_back(make_pair(v, 1));
      } else {
        p[u][0].push_back(make_pair(v, 0));
        p[u][1].push_back(make_pair(v, 0));
      }
    }
  }
}
void solve(int u, int t, vector<int>& ret) {
  for (auto x : p[u][t]) {
    if (x.second) ret.push_back(fa[x.first]);
    solve(x.first, x.second, ret);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(make_pair(v, i));
    g[v].push_back(make_pair(u, i));
  }
  dfs(1);
  if (f[1][0]) {
    vector<int> ans;
    solve(1, 0, ans);
    printf("%d\n", ans.size());
    for (int u : ans) printf("%d ", u);
    putchar('\n');
  } else
    puts("-1");
  return 0;
}
