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;
bool choose[300010];
int N, M;
vector<pair<int, int> > e[300010];
int col[300010];
int sum[300010];
bool vis[300010];
vector<int> p1, p2;
void dfs(int x, int fa) {
  sum[x] = (col[x] == 1);
  for (auto t : e[x])
    if (t.first != fa && !vis[t.first]) {
      vis[t.first] = true;
      dfs(t.first, x);
      if (sum[t.first]) choose[t.second] = true;
      sum[x] ^= sum[t.first];
    }
}
vector<int> ans;
int main() {
  p1.clear();
  p2.clear();
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &col[i]);
    if (col[i] == 1) p1.push_back(i);
    if (col[i] == -1) p2.push_back(i);
  }
  for (int i = 1; i <= M; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[u].push_back(make_pair(v, i));
    e[v].push_back(make_pair(u, i));
  }
  if (p1.size() % 2 == 1 && p2.size() == 0) {
    puts("-1");
    return 0;
  }
  if (p1.size() % 2 == 1) col[p2[0]] = 1;
  memset(vis, false, sizeof(vis));
  memset(choose, false, sizeof(choose));
  vis[1] = true;
  dfs(1, 0);
  for (int i = 1; i <= M; i++)
    if (choose[i]) ans.push_back(i);
  printf("%d\n", ans.size());
  for (auto t : ans) printf("%d\n", t);
}
