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 + 5;
const int K1 = 1;
const int K2 = -1;
vector<int> g[MAXN];
int ee[MAXN][2];
int d[MAXN];
int deg[MAXN];
set<pair<int, int> > st;
bool take[MAXN];
set<pair<pair<int, int>, int> > neigh;
void update(int v, int val) {
  for (int i = 0; i < (int)g[v].size(); i++) {
    int num = g[v][i];
    int to = ee[num][0] == v ? ee[num][1] : ee[num][0];
    if (d[to] == 1) st.erase(make_pair(K1 * deg[to], to));
    deg[to] += val;
    if (d[to] == 1) st.insert(make_pair(K1 * deg[to], to));
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  int v, to;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &v, &to);
    ee[i][0] = v;
    ee[i][1] = to;
    g[v].push_back(i);
    g[to].push_back(i);
  }
  for (int i = 0; i < m; i++) {
    v = ee[i][0];
    to = ee[i][1];
    if (d[v] == -1 && d[to] == 1) {
      d[to] = 0;
      take[i] = 1;
      update(to, -1);
    }
    if (d[to] == -1 && d[v] == 1) {
      d[v] = 0;
      take[i] = 1;
      update(v, -1);
    }
  }
  for (int i = 0; i < m; i++) {
    v = ee[i][0];
    to = ee[i][1];
    if (d[to] == 1) {
      deg[v]++;
    }
    if (d[v] == 1) {
      deg[to]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (d[i] == 1) {
      st.insert(make_pair(K1 * deg[i], i));
    }
  }
  while (!st.empty()) {
    v = st.begin()->second;
    st.erase(st.begin());
    bool found = 0;
    neigh.clear();
    for (int i = 0; i < (int)g[v].size(); i++) {
      int num = g[v][i];
      if (take[num]) continue;
      int to = ee[num][0] == v ? ee[num][1] : ee[num][0];
      if (d[to] == -1) {
        found = 1;
        d[v] = 0;
        update(v, -1);
        take[num] = 1;
        break;
      }
    }
    for (int i = 0; i < (int)g[v].size() && !found; i++) {
      int num = g[v][i];
      if (take[num]) continue;
      int to = ee[num][0] == v ? ee[num][1] : ee[num][0];
      neigh.insert(make_pair(make_pair(-d[to], K2 * deg[to]), num));
    }
    if (found) continue;
    if (neigh.empty()) {
      cout << -1;
      return;
    }
    int num = neigh.begin()->second;
    to = ee[num][0] == v ? ee[num][1] : ee[num][0];
    neigh.erase(neigh.begin());
    take[num] = 1;
    d[v] = 0;
    update(v, -1);
    if (d[to] == 1) {
      st.erase(make_pair(K1 * deg[to], to));
      d[to] = 0;
      update(to, -1);
    } else {
      st.insert(make_pair(K1 * deg[to], to));
      d[to] = 1;
      update(to, 1);
    }
  }
  vector<int> res;
  for (int i = 0; i < m; i++) {
    if (take[i]) res.push_back(i + 1);
  }
  int sz = res.size();
  printf("%d\n", sz);
  for (int i = 0; i < sz; i++) {
    printf("%d\n", res[i]);
  }
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
