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;
const int N = 300000;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
int d[N];
vector<pair<int, int> > g[N];
bool used[N];
vector<int> out;
int dfs(int u) {
  used[u] = true;
  int cnt = d[u];
  for (auto &v : g[u])
    if (!used[v.first]) {
      int x = dfs(v.first);
      if (x & 1) out.push_back(v.second);
      cnt += x;
    }
  return cnt;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> d[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});
  }
  int p = -1, cnt = 0;
  for (int i = 0; i < n; i++)
    if (d[i] == -1)
      p = i;
    else if (d[i] == 1)
      cnt++;
  if ((cnt & 1) && (p == -1)) {
    cout << -1 << "\n";
    return 0;
  }
  if (!(cnt & 1)) p = -1;
  for (int i = 0; i < n; i++)
    if (d[i] == -1 && i != p) d[i] = 0;
  dfs(0);
  cout << (int)out.size() << "\n";
  for (int i : out) cout << i + 1 << " ";
  cout << "\n";
  return 0;
}
