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;
template <class T1, class T2>
inline istream& operator>>(istream& fin, pair<T1, T2>& pr) {
  fin >> pr.first >> pr.second;
  return fin;
}
template <class T0, class T1, class T2>
inline istream& operator>>(istream& fin, tuple<T0, T1, T2>& t) {
  fin >> get<0>(t) >> get<1>(t) >> get<2>(t);
  return fin;
}
template <class T>
inline istream& operator>>(istream& fin, vector<T>& a) {
  for (auto& u : a) fin >> u;
  return fin;
}
template <class T, size_t n>
inline istream& operator>>(istream& fin, array<T, n>& a) {
  for (auto& u : a) fin >> u;
  return fin;
}
template <class FwdIter>
inline auto dump(FwdIter first, FwdIter last, const char* dlm = " ") -> void {
  copy(first, last,
       ostream_iterator<typename iterator_traits<FwdIter>::value_type>(cout,
                                                                       dlm));
}
template <typename T>
vector<T>& operator--(vector<T>& a) {
  for (auto& i : a) --i;
  return a;
}
void run() {
  size_t n, m;
  cin >> n >> m;
  vector<int> d(n);
  cin >> d;
  typedef struct {
    size_t head, tail;
    bool tag;
  } edge_t;
  vector<edge_t> edge(m);
  vector<vector<size_t>> adj(n);
  for (size_t i = 0; i < m; ++i) {
    auto& e = edge[i];
    cin >> e.head >> e.tail;
    --e.head;
    --e.tail;
    e.tag = false;
    adj[e.head].push_back(i);
    adj[e.tail].push_back(i);
  }
  {
    const auto odd = count(begin(d), end(d), 1);
    if (odd & 1) {
      const auto iter = find(begin(d), end(d), -1);
      if (iter == end(d)) {
        cout << -1;
        return;
      }
      *iter = 1;
    }
  }
  vector<size_t> par(n, -1);
  vector<size_t> dist(n, 0);
  dist[0] = par[0] = 0;
  {
    queue<size_t> q;
    for (q.push(0); !q.empty(); q.pop()) {
      const auto r = q.front();
      for (const auto i : adj[r]) {
        const auto& e = edge[i];
        const auto v = e.head + e.tail - r;
        if (par[v] == (size_t)-1) {
          par[v] = r;
          dist[v] = dist[r] + 1;
          q.push(v);
        }
      }
    }
  };
  ;
  priority_queue<pair<size_t, size_t>, vector<pair<size_t, size_t>>> heap;
  for (size_t i = 0; i < n; ++i)
    if (d[i] == 1) heap.push({dist[i], i});
  vector<size_t> deg(n);
  size_t cnt = 0;
  while (!heap.empty()) {
    const auto pr = heap.top();
    heap.pop();
    const auto v = pr.second;
    if (d[v] == 1 && (deg[v] & 1)) continue;
    if (v == 0) continue;
    const auto r = par[v];
    ++deg[r];
    ++deg[v];
    ++cnt;
    for (const auto i : adj[v])
      if (edge[i].head + edge[i].tail == v + r) {
        edge[i].tag = true;
        break;
      }
    if (d[r] != 1) heap.push({dist[r], r});
  }
  cout << cnt << '\n';
  for (size_t i = 0; i < edge.size(); ++i)
    if (edge[i].tag) cout << i + 1 << '\n';
}
int main(const int argc, char* argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  run();
  return EXIT_SUCCESS;
}
