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;
long long const MAXN = 3e5 + 8;
long long const INF = 1e12 + 8;
long long const delta = 1000000007;
set<long long> edges[MAXN];
long long a[MAXN];
long long mark2[MAXN];
pair<long long, long long> e[MAXN];
set<long long> ans;
long long p;
void dfs(long long v, long long start) {
  if (a[v] == 1 && v != start || a[v] == -1) {
    p = 1;
    if (a[v] == 1) a[v] = 0;
    return;
  }
  while (edges[v].size()) {
    long long t = *edges[v].begin();
    edges[v].erase(t);
    long long u = e[t].first;
    if (u == v) u = e[t].second;
    edges[u].erase(t);
    if (!mark2[u]) dfs(u, start);
    if (p) {
      ans.insert(t);
      break;
    }
  }
  if (!p) {
    mark2[v] = 1;
  }
  if (p && v == start) {
    a[v] = 0;
  }
}
int main() {
  std::ios::sync_with_stdio(0);
  ;
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  long long f, s;
  for (long long i = 0; i < m; i++) {
    cin >> f >> s;
    edges[f].insert(i);
    edges[s].insert(i);
    e[i] = make_pair(f, s);
  }
  for (long long i = 1; i <= n; i++) {
    if (a[i] == 1) {
      p = 0;
      dfs(i, i);
      if (!p) return cout << -1, 0;
    }
  }
  cout << ans.size() << endl;
  for (set<long long>::iterator i = ans.begin(); i != ans.end(); i++)
    cout << (*i) + 1 << endl;
  return 0;
}
