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 + 5;
int n, m;
int v[N];
vector<int> g[N], id[N];
bool viz[N];
int dad[N], what[N];
int stk[N], vf = 0;
inline void build(int nod) {
  viz[nod] = 1;
  int p = 0;
  for (auto nou : g[nod]) {
    if (viz[nou] == 0) {
      dad[nou] = nod;
      what[nou] = id[nod][p];
      build(nou);
    }
    p++;
  }
  stk[++vf] = nod;
}
vector<int> ans;
inline void dfs(int nod) {
  viz[nod] = 1;
  if (v[nod] % 2 == 1) {
    ans.push_back(what[nod]);
    v[nod]++;
    v[dad[nod]]++;
    dfs(dad[nod]);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b), id[a].push_back(i);
    g[b].push_back(a), id[b].push_back(i);
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (v[i] == 1) {
      cnt++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (v[i] == -1) {
      v[i] = cnt % 2;
      cnt += v[i];
    }
  }
  if (cnt % 2) {
    cout << "-1\n";
    return 0;
  }
  build(1);
  for (int i = 1; i <= n; i++) {
    viz[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    int nod = stk[i];
    if (viz[nod] == 0) {
      dfs(nod);
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << "\n";
  for (auto x : ans) {
    cout << x << "\n";
  }
  return 0;
}
