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;
unordered_set<int> V;
int root;
int R;
int D[300010];
vector<vector<int> > G;
vector<vector<int> > IDX;
vector<int> sol;
bool rec = 0;
int Q;
bool dfs(int n, int p) {
  for (int k = 0; k < G[n].size(); k++) {
    int id = IDX[n][k];
    if (id == p) continue;
    int v = G[n][k];
    if (V.find(v) != V.end()) {
      if (v == root) {
        if (R != 1) {
          rec = 1;
          Q = root;
          sol.push_back(id);
          return 1;
        }
      } else {
        rec = 1;
        Q = v;
        sol.push_back(id);
        return 1;
      }
    } else if (D[v] != 0) {
      rec = 1;
      Q = root;
      sol.push_back(id);
      return 1;
    } else {
      V.insert(v);
      bool ok = dfs(v, id);
      V.erase(v);
      if (ok == 1) {
        if (rec) sol.push_back(id);
        if (n == Q) rec = 0;
        return 1;
      }
    }
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  R = 0;
  for (int i = 1; i <= N; i++) {
    cin >> D[i];
    if (D[i] == -1) {
      R = -1;
      root = i;
    } else if (D[i] == 1) {
      if (R != -1) {
        R = 1;
        root = i;
      }
    } else {
      if (R == 0) {
        root = i;
      }
    }
  }
  G.resize(N + 1);
  IDX.resize(N + 1);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
    IDX[a].push_back(i + 1);
    IDX[b].push_back(i + 1);
  }
  V.insert(root);
  bool ok = dfs(root, -1);
  if (ok) {
    cout << sol.size() << endl;
    for (int i = 0; i < sol.size(); i++) {
      if (i != 0) cout << ' ';
      cout << sol[i];
    }
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
