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 int64_t infll = 9223372036854775807LL;
struct solver {
  int64_t n;
  int64_t m;
  vector<int64_t> d;
  vector<vector<pair<int64_t, int64_t>>> adj;
  vector<vector<pair<int64_t, int64_t>>> adj2;
  vector<bool> visited;
  vector<int64_t> ans;
  void solve() {
    cin >> n >> m;
    d.resize(n + 1);
    adj.resize(n + 1);
    adj2.resize(n + 1);
    visited.assign(n + 1, false);
    int64_t x, y;
    for (int64_t i = (1); i <= (n); ++i) {
      cin >> d[i];
    }
    for (int64_t i = (0); i < (m); ++i) {
      cin >> x >> y;
      adj[x].push_back({y, i + 1});
      adj[y].push_back({x, i + 1});
    }
    int64_t lastneg1idx = -1;
    int64_t ss = 0;
    for (int64_t i = (1); i <= (n); ++i) {
      if (d[i] == -1) {
        d[i] = 0;
        lastneg1idx = i;
      }
      if (d[i] == 1) ss++;
    }
    if (lastneg1idx == -1 && (ss & 1) == 1) {
      cout << "-1\n";
      return;
    }
    if (ss & 1) {
      d[lastneg1idx] = 1;
    }
    makeSpanningTree(1, -1);
    dfs2(1, -1);
    cout << ans.size() << "\n";
    for (auto p : ans) {
      cout << p << "\n";
    }
  }
  void makeSpanningTree(int64_t nn, int64_t par) {
    visited[nn] = true;
    for (auto pp : adj[nn]) {
      int64_t nn2 = pp.first;
      int64_t idx = pp.second;
      if (nn2 == par) continue;
      if (visited[nn2]) continue;
      visited[nn2] = true;
      adj2[nn].push_back({nn2, idx});
      adj2[nn2].push_back({nn, idx});
      makeSpanningTree(nn2, nn);
    }
  }
  void dfs2(int64_t nn, int64_t par) {
    int64_t paredge = -1;
    for (auto pp : adj2[nn]) {
      int64_t nn2 = pp.first;
      int64_t idx = pp.second;
      if (nn2 == par) {
        paredge = idx;
      } else {
        dfs2(nn2, nn);
      }
    }
    if (par >= 0) {
      if ((int64_t)(adj2[nn].size() % 2) == d[nn]) {
        ans.push_back(paredge);
      } else {
        d[par] = (d[par] == 1 ? 0 : 1);
      }
    }
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(15);
  solver s;
  s.solve();
  return 0;
}
