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>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
inline long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
inline long long power(long long a, long long n, long long m) {
  if (n == 0) return 1;
  long long p = power(a, n / 2, m);
  p = (p * p) % m;
  if (n % 2)
    return (p * a) % m;
  else
    return p;
}
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
set<pair<int, int> > st;
struct subset {
  int parent, rank;
};
int find(subset subsets[], int i) {
  if (subsets[i].parent == i) return i;
  subsets[i].parent = find(subsets, subsets[i].parent);
  return subsets[i].parent;
}
void Union(subset subsets[], int x, int y) {
  if (subsets[x].rank > subsets[y].rank) {
    subsets[y].parent = x;
  } else if (subsets[x].parent < subsets[y].parent) {
    subsets[x].parent = y;
  } else {
    subsets[y].parent = x;
    subsets[x].rank++;
  }
}
void dfs(vector<int> adj[], int u, int d[], int p) {
  int v;
  for (int i = 0; i < adj[u].size(); i++) {
    v = adj[u][i];
    if (p != v) {
      dfs(adj, v, d, u);
      if (d[v]) {
        st.insert(make_pair(min(u, v), max(u, v)));
        d[u] = (!d[u]);
      }
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  int d[n];
  int s = 0;
  int u, v = -1;
  memset(d, 0, sizeof(d));
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    if (d[i] != -1)
      s += d[i];
    else
      v = i;
  }
  if (s % 2) {
    if (v == -1) {
      cout << -1 << endl;
      return 0;
    } else
      d[v] = 1;
  }
  for (int i = 1; i <= n; i++)
    if (d[i] == -1) d[i] = 0;
  vector<pair<int, int> > edge;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    edge.push_back(make_pair(min(u, v), max(u, v)));
  }
  subset subsets[n + 1];
  int x, y;
  vector<int> adj[n + 1];
  for (int i = 0; i <= n; i++) {
    subsets[i].rank = 0;
    subsets[i].parent = i;
  }
  for (int i = 0; i < m; i++) {
    u = edge[i].first;
    v = edge[i].second;
    x = find(subsets, u);
    y = find(subsets, v);
    if (x != y) {
      Union(subsets, x, y);
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
  }
  dfs(adj, 1, d, 0);
  set<pair<int, int> >::iterator it;
  vector<int> ans;
  for (int i = 0; i < m; i++) {
    u = edge[i].first;
    v = edge[i].second;
    it = st.find(make_pair(min(u, v), max(u, v)));
    if (it != st.end()) {
      ans.push_back(i + 1);
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
  return 0;
}
