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<unordered_set<int> > E;
int D[300010];
int F[300010];
int T[300010];
vector<int> sol;
unordered_set<int> V;
bool dfs(int n) {
  for (auto it : E[n]) {
    int a = n;
    int b = F[it] + T[it] - n;
    if (V.find(b) != V.end()) continue;
    if (D[b] != 0) {
      sol.push_back(it);
      E[a].erase(it);
      E[b].erase(it);
      if (D[b] == 1) D[b] = 0;
      return 1;
    }
    V.insert(b);
    bool ok = dfs(b);
    if (ok) {
      sol.push_back(it);
      E[a].erase(it);
      E[b].erase(it);
      return 1;
    }
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  E.resize(N + 1);
  for (int i = 1; i <= N; i++) cin >> D[i];
  for (int i = 1; i <= M; i++) {
    int a, b;
    cin >> a >> b;
    F[i] = a;
    T[i] = b;
    E[a].insert(i);
    E[b].insert(i);
  }
  for (int i = 1; i <= N; i++) {
    if (D[i] == 1) {
      V.clear();
      V.insert(i);
      bool ok = dfs(i);
      if (!ok) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << sol.size() << endl;
  for (int i = 0; i < sol.size(); i++) {
    if (i != 0) cout << ' ';
    cout << sol[i];
  }
  cout << endl;
  return 0;
}
