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;
vector<pair<int, int> > v[300010];
vector<int> u[300010];
int n, m, i, CNT, cnt1, cnt2, d[300010], t[300010], dist[300010], edge[300010],
    x[300010], y[300010];
bool in[300010], used[300010];
deque<int> q;
int dfs(int poz) {
  int cnt = 0;
  for (auto it : u[poz]) cnt += dfs(it);
  if (d[poz] == -1) return 0;
  if (d[poz] != (cnt & 1)) {
    used[edge[poz]] = 1;
    CNT++;
    return 1;
  }
  return 0;
}
void dfs2(int poz) {
  for (auto it : u[poz]) {
    dfs(it);
    dist[poz] += dist[it];
  }
  dist[poz] += (d[poz] == 1);
  if (t[poz] != -1)
    if (dist[poz] & 1) used[edge[poz]] = 1, CNT++;
}
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> d[i];
    if (d[i] == -1) cnt1 = i;
    if (d[i] == 1) cnt2++;
  }
  for (i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
    v[x[i]].push_back({y[i], i});
    v[y[i]].push_back({x[i], i});
  }
  if (cnt1) {
    memset(dist, 127, sizeof(dist));
    dist[cnt1] = 0;
    t[cnt1] = -1;
    in[cnt1] = 1;
    q.push_back(cnt1);
    while (q.size()) {
      int aux = q.front();
      q.pop_front();
      in[aux] = 0;
      for (auto it : v[aux])
        if (it.first != t[aux])
          if (dist[it.first] > dist[aux] + 1) {
            dist[it.first] = dist[aux] + 1;
            t[it.first] = aux;
            edge[it.first] = it.second;
            if (!in[it.first]) {
              in[it.first] = 1;
              q.push_back(it.first);
            }
          }
    }
    for (i = 1; i <= n; i++)
      if (t[i] != -1) u[t[i]].push_back(i);
    dfs(cnt1);
    cout << CNT << '\n';
    for (i = 1; i <= m; i++)
      if (used[i]) cout << i << '\n';
    return 0;
  }
  if (cnt2 & 1) {
    cout << -1;
    return 0;
  }
  for (i = 1; i <= n; i++)
    if (d[i] == 1) {
      cnt1 = i;
      break;
    }
  memset(dist, 127, sizeof(dist));
  dist[cnt1] = 0;
  t[cnt1] = -1;
  in[cnt1] = 1;
  q.push_back(cnt1);
  while (q.size()) {
    int aux = q.front();
    q.pop_front();
    in[aux] = 0;
    for (auto it : v[aux])
      if (it.first != t[aux])
        if (dist[it.first] > dist[aux] + 1) {
          dist[it.first] = dist[aux] + 1;
          t[it.first] = aux;
          edge[it.first] = it.second;
          if (!in[it.first]) {
            in[it.first] = 1;
            q.push_back(it.first);
          }
        }
  }
  for (i = 1; i <= n; i++)
    if (t[i] != -1) u[t[i]].push_back(i);
  memset(dist, 0, sizeof(dist));
  dfs2(cnt1);
  cout << CNT << '\n';
  for (i = 1; i <= m; i++)
    if (used[i]) cout << i << '\n';
  return 0;
}
