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 N = 300000 + 10;
int n, m, d[N];
vector<pair<int, int> > g[N], tree[N];
bool vis[N];
void dfs(int u) {
  vis[u] = 1;
  for (auto e : g[u]) {
    int v = e.first;
    if (vis[v] == 0) {
      tree[u].push_back(make_pair(v, e.second));
      tree[v].push_back(make_pair(u, e.second));
      dfs(v);
    }
  }
}
int sz1[N], sz2[N];
void getsiz(int u, int p) {
  for (auto e : tree[u]) {
    int v = e.first;
    if (p == v) continue;
    getsiz(v, u);
    sz1[u] += sz1[v];
    sz2[u] += sz2[v];
  }
}
vector<int> ans;
vector<int> v1, v_1;
void gen(int u, int p) {
  for (auto e : tree[u]) {
    int v = e.first;
    if (p == v) continue;
    long long tot = 1LL * sz1[v] * (v1.size() / 2 - sz2[v]) +
                    1LL * sz2[v] * (v1.size() / 2 - sz1[v]);
    if (tot % 2 == 1) ans.push_back(e.second);
    gen(v, u);
  }
}
int main() {
  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);
  for (int i = 1; i <= n; i++) {
    if (d[i] == 1) v1.push_back(i);
    if (d[i] == -1) v_1.push_back(i);
  }
  if (v1.size() % 2 == 1) {
    if (v_1.size() == 0) return !printf("-1\n");
    v1.push_back(v_1[0]);
  }
  for (int i = 0; i < v1.size(); i += 2) {
    sz1[v1[i]]++;
    sz2[v1[i + 1]]++;
  }
  getsiz(1, 1);
  gen(1, 1);
  printf("%d\n", ans.size());
  for (auto x : ans) printf("%d ", x);
  printf("\n");
}
