#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
long long mod = 1e9 + 7;
const long long INF = 1e18;
const double eps = 1e-6;
const int maxn = 3e5 + 5;
template <class T>
inline bool scan_d(T &ret) {
  char c;
  int sgn;
  if (c = getchar(), c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
inline void out(long long x) {
  if (x > 9) out(x / 10);
  putchar(x % 10 + '0');
}
vector<pair<int, int> > G[maxn];
int d[maxn];
int du[maxn];
vector<int> ans;
bool vis[maxn];
void dfs(int u) {
  vis[u] = true;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i].first;
    if (vis[v]) continue;
    dfs(v);
    if (du[v] % 2 != d[v]) {
      du[v]++;
      du[u]++;
      ans.push_back(G[u][i].second);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int one = 0;
  int a = -1;
  int b = -1;
  memset(du, 0, sizeof(du));
  memset(vis, false, sizeof(vis));
  for (int i = 0; i < n; i++) {
    scanf("%d", &d[i]);
    one += (d[i] == 1);
    a = d[i] == -1 ? i : a;
    b = d[i] == 1 ? i : b;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    G[x - 1].push_back(pair<int, int>(y - 1, i));
    G[y - 1].push_back(pair<int, int>(x - 1, i));
  }
  if (a == -1 && one & 1) {
    puts("-1");
    return 0;
  }
  if (a != -1) {
    dfs(a);
  } else if (b != -1) {
    dfs(b);
  } else {
    puts("0");
    return 0;
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) {
    printf("%d ", ans[i] + 1);
  }
}
