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>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
using llong = long long;
using ld = long double;
using ii = pair<int, int>;
using ull = unsigned long long;
using pll = pair<llong, llong>;
const llong over999 = 1e16;
const llong md = 1e9 + 7;
const ld eps = 1e-9;
const ld Pi = acos(-1);
vector<ii> gr[300100];
int p[300100], take[300100], need[300100], cnt[300100], f[300100], now[300100];
bool have_minus;
vector<int> ans;
vector<pair<pair<int, int>, int>> v;
int get_p(int x) { return ((p[x] == x) ? x : p[x] = get_p(p[x])); }
void unite(int x, int y) {
  if (rand() & 1) swap(x, y);
  p[x] = p[y];
}
void dfs(int x, int p, int num) {
  for (auto i : gr[x]) {
    if (p == i.first) continue;
    dfs(i.first, x, i.second);
  }
  if ((f[x] != -1 && now[x] != f[x]) || need[x]) {
    take[num] ^= 1;
    if (f[p] != -1) need[p] ^= 1;
    now[x] ^= 1;
    now[p] ^= 1;
  }
}
int n, m, x, y, it;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> f[i];
    if (f[i] == -1) have_minus = true, it = i;
  }
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    cnt[x]++;
    cnt[y]++;
    v.push_back({{x, y}, i});
  }
  if (!have_minus) {
    int calc = 0;
    for (int i = 1; i <= n; i++) {
      if (cnt[i] % 2 != f[i]) calc++;
    }
    if (calc & 1) return cout << -1, 0;
  }
  for (int i = 1; i <= n; i++) {
    p[i] = i;
  }
  for (auto i : v) {
    x = i.first.first, y = i.first.second;
    int num = i.second;
    int p_x = get_p(x);
    int p_y = get_p(y);
    if (p_x != p_y) {
      take[num] = 1;
      now[x] ^= 1;
      now[y] ^= 1;
      unite(p_x, p_y);
      gr[x].push_back({y, num});
      gr[y].push_back({x, num});
    }
  }
  if (!have_minus) it = 1;
  for (auto i : gr[it]) {
    dfs(i.first, it, i.second);
  }
  for (int i = 0; i < m; i++) {
    if (take[i]) ans.push_back(i + 1);
  }
  cout << ans.size() << endl;
  for (auto i : ans) {
    cout << i << endl;
  }
  return 0;
}
