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<pair<int, int> > adj[3000000 + 342];
int val[3000000 + 342];
vector<int> ans;
bool vis[3000000 + 342];
bool dfs(int cur) {
  if (vis[cur]) {
    return true;
  }
  vis[cur] = true;
  int degree = 0;
  for (int i = 0; i < adj[cur].size(); i++) {
    int next = adj[cur][i].second;
    if (!dfs(next)) {
      degree++;
      ans.push_back(adj[cur][i].first);
    }
  }
  if (val[cur] == -1 || degree % 2 == val[cur]) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> val[i];
  int x, y;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    adj[x].push_back(make_pair(i, y));
    adj[y].push_back(make_pair(i, x));
  }
  if (dfs(1) == false) {
    cout << -1;
    return 0;
  }
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
