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;
int a[300001];
int par[300001];
vector<int> adj[300001];
bool vis[300001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  vector<int> leaf;
  vector<pair<int, int>> ans;
  map<pair<int, int>, int> ma;
  int n, m, sum = 0;
  cin >> n >> m;
  bool b = true;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] >= 0) {
      sum += a[i];
    }
    if (a[i] == -1) {
      b = false;
    }
  }
  if (b && sum % 2 == 1) {
    cout << -1;
    return 0;
  }
  bool first = true;
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1) {
      if (sum % 2 == 1 && first) {
        a[i] = 1;
      } else {
        a[i] = 0;
      }
      first = false;
    }
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    if (!ma.count(make_pair(u, v))) {
      ma.insert(make_pair(make_pair(u, v), i));
    }
    if (!ma.count(make_pair(v, u))) {
      ma.insert(make_pair(make_pair(v, u), i));
    }
  }
  queue<int> q;
  q.push(1);
  par[1] = 0;
  while (!q.empty()) {
    int t = q.front();
    vis[t] = true;
    bool l = false;
    for (int i : adj[t]) {
      if (!vis[i]) {
        par[i] = t;
        q.push(i);
        l = true;
        vis[i] = true;
      }
    }
    if (!l) {
      leaf.push_back(t);
    }
    q.pop();
  }
  for (int i : leaf) {
    int k = i;
    while (par[k] != 0) {
      assert(a[k] != -1);
      if (a[k] == 1) {
        a[par[k]] = (a[par[k]] + 1) % 2;
        ans.push_back(make_pair(k, par[k]));
      }
      k = par[k];
    }
  }
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++) {
    cout << ma[make_pair(ans[i].first, ans[i].second)] << "\n";
  }
  return 0;
}
