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 = 3e5 + 7;
struct node {
  int to;
  int indx;
};
int n, m;
int dig[MAXN];
vector<node> mmap[MAXN];
int cnt;
bool vis[MAXN];
int ans[MAXN];
void dfs(int now, int dep) {
  int len = mmap[now].size();
  bool flag = false;
  for (int i = 0; i <= len - 1; ++i)
    if (!vis[mmap[now][i].to]) {
      flag = true;
      int to = mmap[now][i].to;
      vis[to] = true;
      dfs(to, dep + 1);
      if (dig[to]) ans[cnt++] = mmap[now][i].indx;
      dig[now] ^= dig[to];
    }
}
int main() {
  scanf("%d%d", &n, &m);
  int ck = 0;
  bool flag = false;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &dig[i]);
    if (dig[i] != -1)
      ck += dig[i];
    else
      flag = true;
  }
  if (!flag && (ck & 1)) {
    printf("-1\n");
    return 0;
  }
  if (ck & 1)
    flag = true;
  else
    flag = false;
  for (int i = 1; i <= n; ++i)
    if (flag && dig[i] == -1) {
      dig[i] = 1;
      flag = false;
    } else if (!flag && dig[i] == -1)
      dig[i] = 0;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    node tp;
    tp.to = v;
    tp.indx = i;
    mmap[u].push_back(tp);
    tp.to = u;
    mmap[v].push_back(tp);
  }
  vis[1] = true;
  cnt = 0;
  dfs(1, 0);
  printf("%d\n", cnt);
  if (cnt > 0)
    for (int i = 0; i <= cnt - 1; ++i) printf("%d\n", ans[i]);
  return 0;
}
