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 int N = 3e5 + 7;
int val[N];
vector<pair<int, int> > G[N];
vector<int> ans;
int vis[N];
void init() {
  for (int i = 0; i < N; i++) G[i].clear();
}
void add_edge(int u, int v, int d) {
  G[u].push_back(make_pair(v, d));
  G[v].push_back(make_pair(u, d));
}
bool dfs(int u) {
  vis[u] = 1;
  int sz = 0;
  for (auto temp : G[u]) {
    int v = temp.first;
    if (vis[v]) continue;
    sz++;
    if (val[v] == 0) {
      if (dfs(v)) {
        ans.push_back(temp.second);
        return true;
      }
    } else if (val[v] == -1 || val[v] == 1) {
      ans.push_back(temp.second);
      return true;
    }
  }
  if (!sz && (val[u] == -1 || val[u] == 1)) return true;
  return false;
}
int main() {
  ios ::sync_with_stdio(false);
  int n, m;
  while (cin >> n >> m) {
    init();
    int flag = 0;
    for (int i = 1; i <= n; i++) {
      cin >> val[i];
      if (val[i] == 1) flag = 1;
    }
    for (int i = 1; i <= m; i++) {
      int u, v;
      cin >> u >> v;
      add_edge(u, v, i), add_edge(v, u, i);
    }
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; i++) {
      if (vis[i]) continue;
      ans.clear();
      if (val[i] == -1 || val[i] == 1)
        if (dfs(i)) break;
    }
    if (ans.size() == 0 && flag) {
      cout << -1 << endl;
      continue;
    }
    cout << ans.size() << endl;
    for (auto x : ans) cout << x << endl;
  }
}
