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 = 3e5 + 5;
struct Edge {
  int v, i;
};
vector<Edge> edge[N];
vector<int> c1, c2;
int n, m;
int d[N];
bool vis[N], flag[N];
vector<int> ans;
void dfs(int u) {
  vis[u] = 1;
  for (auto& e : edge[u]) {
    if (vis[e.v]) continue;
    dfs(e.v);
    if (flag[e.v]) ans.push_back(e.i);
    flag[u] ^= flag[e.v];
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    if (d[i] == 1)
      c1.push_back(i);
    else if (d[i] == -1)
      c2.push_back(i);
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edge[u].push_back(Edge{v, i});
    edge[v].push_back(Edge{u, i});
  }
  if (c1.size() % 2 && c2.empty()) {
    puts("-1");
    return 0;
  }
  int k = c1.size() / 2;
  for (int i = 0; i < k; i++) {
    flag[c1[i]] = flag[c1[k + i]] = 1;
  }
  if (c1.size() % 2) {
    flag[c1[c1.size() - 1]] = flag[c2[0]] = 1;
  }
  dfs(1);
  printf("%d\n", ans.size());
  for (auto& x : ans) printf("%d ", x);
  puts("");
}
