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 = 1e6;
vector<int> G[maxn];
map<pair<int, int>, int> f;
int vis[maxn], up[maxn], siz[maxn];
int a[maxn], ans[maxn];
struct node {
  int u, v;
} s[maxn];
void dfs(int root) {
  vis[root] = 1;
  int leaf = 1;
  int sz = G[root].size();
  for (int i = 0; i < sz; i++) {
    int y = G[root][i];
    if (vis[y]) continue;
    dfs(y);
    if (up[y] == 1) {
      f[make_pair(root, y)] = 1;
      f[make_pair(y, root)] = 1;
      siz[root]++;
    }
    leaf = 0;
  }
  if (leaf == 1) {
    if (a[root] == 0)
      up[root] = 0;
    else
      up[root] = 1;
  } else {
    if (a[root] == 0) {
      if (siz[root] & 1)
        up[root] = 1;
      else
        up[root] = 0;
    } else {
      if (siz[root] & 1)
        up[root] = 0;
      else
        up[root] = 1;
    }
  }
}
int main() {
  int n, m;
  int root = 1;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == -1) root = i;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &s[i].u, &s[i].v);
    G[s[i].v].push_back(s[i].u);
    G[s[i].u].push_back(s[i].v);
  }
  dfs(root);
  if (a[root] == -1 || up[root] == 0) {
    int cnt = 0;
    for (int i = 1; i <= m; i++) {
      int u = s[i].u, v = s[i].v;
      if (f[make_pair(u, v)] || f[make_pair(v, u)]) {
        ans[++cnt] = i;
        f[make_pair(u, v)] = 0;
        f[make_pair(v, u)] = 0;
      }
    }
    printf("%d\n", cnt);
    for (int i = 1; i <= cnt; i++) printf("%d\n", ans[i]);
  } else
    printf("-1\n");
}
