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[300300];
bool used[300300];
bool t[300300][2];
vector<int> s[300300][2];
vector<int> num[300300][2];
vector<pair<int, int> > g[300300];
bool ist = true;
void dfs(int v) {
  if (!ist) {
    return;
  }
  used[v] = true;
  int d1 = 0, d2 = -1, nu = -1;
  for (auto u1 : g[v]) {
    int u = u1.first;
    if (!used[u]) {
      dfs(u);
      if (t[u][0] && t[u][1] || a[u] == -1) {
        d2 = u1.second;
        nu = u;
      } else {
        if (t[u][a[u]] == 0) {
          d1++;
          s[v][0].push_back(u1.second);
          num[v][0].push_back(u);
          s[v][1].push_back(u1.second);
          num[v][1].push_back(u);
        }
      }
    }
  }
  if (d1 % 2 == 0) {
    t[v][0] = true;
    if (d2 != -1) {
      s[v][1].push_back(d2);
      num[v][1].push_back(nu);
      t[v][1] = true;
    }
  } else {
    t[v][1] = true;
    if (d2 != -1) {
      s[v][0].push_back(d2);
      num[v][0].push_back(nu);
      t[v][0] = true;
    }
  }
}
vector<int> ans;
bool used1[300300];
void mans(int v, int y) {
  used1[v] = true;
  for (auto z : s[v][y]) {
    ans.push_back(z);
  }
  for (auto u : num[v][y]) {
    int i = u;
    if (a[i] == -1) {
      if (t[i][0]) {
        mans(i, 0);
      } else {
        mans(i, 1);
      }
      continue;
    }
    mans(u, a[u] ^ 1);
  }
}
int main() {
  int n, m, v, u;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    g[u - 1].push_back({v - 1, i});
    g[v - 1].push_back({u - 1, i});
  }
  dfs(0);
  if (a[0] != -1 && t[0][a[0]] == 0) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (!used1[i]) {
      if (a[i] == -1) {
        if (t[i][0]) {
          mans(i, 0);
        } else {
          mans(i, 1);
        }
        continue;
      }
      mans(i, a[i]);
    }
  }
  cout << ans.size() << "\n";
  for (auto z : ans) {
    cout << z + 1 << "\n";
  }
  return 0;
}
