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 MAX_N = 1e6 + 10;
int n, m, d[MAX_N], odd, neg;
vector<int> v[MAX_N], ind[MAX_N];
bool mark[MAX_N];
vector<int> ans;
bool dfs(int u) {
  mark[u] = true;
  int cnt = 0;
  for (int i = 0; i < v[u].size(); i++) {
    int w = v[u][i];
    int z = ind[u][i];
    if (!mark[w])
      if (dfs(w)) {
        ans.push_back(z);
        cnt++;
      }
  }
  if (cnt % 2 == 1 && d[u] == 1) return 0;
  if (cnt % 2 == 1 || d[u] == 1) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    if (d[i] == 1) odd++;
    if (d[i] == -1) neg++;
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    ind[a].push_back(i);
    ind[b].push_back(i);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  if (odd == 0) {
    cout << 0;
    return 0;
  }
  if (odd % 2 == 1 && neg == 0) {
    cout << -1;
    return 0;
  }
  if (odd % 2 == 1) {
    for (int i = 1; i <= n; i++) {
      if (d[i] == -1) {
        d[i] = 1;
        break;
      }
    }
  }
  dfs(1);
  int p = ans.size();
  cout << p << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
}
