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;
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
long long pow_mod(long long x, long long n, long long mod) {
  long long ret = 1LL;
  while (n) {
    if (n & 1) ret = ret * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return ret;
}
const int inf = 0x3f3f3f3f;
const long long INF = (1LL << 62) - 1;
const long long mod = 1e9 + 7;
const int N = 1e6 + 5;
int n, m;
int d[N];
vector<pair<int, int> > E[N];
vector<int> ans;
int cnt[3];
bool vis[N];
int dfs(int u) {
  if (vis[u]) return 0;
  vis[u] = 1;
  int tmp = 0;
  if (d[u] == 1) tmp = 1;
  for (int i = 0; i < E[u].size(); i++) {
    int v = E[u][i].first;
    int ret = dfs(v);
    if (ret) ans.push_back(E[u][i].second);
    tmp ^= ret;
  }
  return tmp;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    if (d[i] == -1)
      cnt[2]++;
    else
      cnt[d[i]]++;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    E[u].push_back({v, i});
    E[v].push_back({u, i});
  }
  if (cnt[1] % 2 == 1) {
    if (cnt[2] % 2 == 0) return 0 * puts("-1");
    for (int i = 1; i <= n; i++) {
      if (d[i] == -1) {
        d[i] = 1;
        break;
      }
    }
  }
  dfs(1);
  int sz = ans.size();
  printf("%d\n", sz);
  sort(ans.begin(), ans.end());
  for (int i = 0; i < sz; i++) printf("%d\n", ans[i]);
  return 0;
}
