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;
long long int n, m, deg[300005], a[300005];
pair<long long int, long long int> ed[300005];
bool check(long long int x) {
  if (a[x] == -1) return true;
  if (a[x] == 1)
    return deg[x] % 2;
  else
    return deg[x] % 2 == 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (long long int i = 1; i <= n; ++i) cin >> a[i];
  for (long long int i = 1; i <= m; ++i)
    cin >> ed[i].first >> ed[i].second, deg[ed[i].first]++, deg[ed[i].second]++;
  if (n == 1) {
    if (a[1] == 0)
      cout << "0\n";
    else
      cout << -1 << '\n';
    return 0;
  }
  vector<long long int> ans;
  for (long long int i = 1; i <= m; ++i) {
    long long int u = ed[i].first, v = ed[i].second;
    if (a[u] == -1 && a[v] == -1) {
      ans.push_back(i);
      continue;
    }
    if (a[v] == -1) swap(u, v);
    if (a[u] == -1) {
      if (a[v] == 1) {
        if (deg[v] % 2)
          ans.push_back(i);
        else {
          deg[v]--;
          deg[u]--;
        }
      } else {
        if (deg[v] % 2 == 0)
          ans.push_back(i);
        else {
          deg[v]--;
          deg[u]--;
        }
      }
    } else {
      long long int cu = check(u), cv = check(v);
      if (cu || cv)
        ans.push_back(i);
      else {
        deg[u]--;
        deg[v]--;
      }
    }
  }
  bool notpos = 0;
  for (long long int i = 1; i <= n; ++i)
    if (!check(i)) notpos = 1;
  if (notpos) {
    cout << -1 << '\n';
    return 0;
  }
  cout << ans.size() << '\n';
  for (long long int v : ans) cout << v << '\n';
}
