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<vector<pair<int, int>>> g;
vector<int> d;
vector<bool> used;
vector<int> cur;
vector<int> ans;
void dfs(int v, pair<int, int> be) {
  used[v] = true;
  for (auto u : g[v]) {
    if (!used[u.first]) {
      dfs(u.first, {v, u.second});
    }
  }
  if (d[v] != -1 && d[v] != cur[v]) {
    if (be.second == -1) {
      cout << -1;
      exit(0);
    }
    cur[v]++;
    cur[v] &= 1;
    cur[be.first]++;
    cur[be.first] &= 1;
    ans.push_back(be.second);
  }
}
int main() {
  cin.tie();
  cout.tie();
  int n, m;
  cin >> n >> m;
  d.resize(n);
  g.resize(n);
  used.resize(n);
  cur.resize(n);
  int st = 0;
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
    if (d[i] == -1) {
      st = i;
    }
  }
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  dfs(st, {-1, -1});
  cout << ans.size() << endl;
  for (auto el : ans) {
    cout << el + 1 << endl;
  }
  return 0;
}
