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 maxn = 4e5 + 11;
int n, m;
struct Node {
  int p;
  int len;
  Node(int _p, int _len) : p(_p), len(_len) {}
};
int list[maxn];
vector<Node> G[maxn];
vector<int> ins;
void add(int x, int y, int len) { G[x].push_back(Node(y, len)); }
int vis[maxn];
int dfs(int x, int fa) {
  vis[x] = 1;
  for (int i = 0; i < G[x].size(); i++) {
    int p = G[x][i].p;
    if (p == fa || vis[p]) continue;
    dfs(p, x);
    list[x] ^= list[p];
    if (list[p]) ins.push_back(G[x][i].len);
  }
  return 0;
}
int main() {
  cin >> n >> m;
  int pos = -1;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    cin >> list[i];
    if (list[i] == -1) pos = i;
    if (list[i] == 1) {
      cnt++;
      list[i] = 1;
    }
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    add(x, y, i);
    add(y, x, i);
  }
  if (cnt == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (cnt % 2 == 1 && pos == -1) {
    cout << -1 << endl;
    return 0;
  }
  if (cnt & 1) {
    list[pos] = 1;
  }
  dfs(1, -1);
  cout << ins.size() << endl;
  for (int i = 0; i < ins.size(); i++) {
    cout << ins[i] << endl;
  }
  return 0;
}
