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 used[300005];
int D[300005];
vector<pair<int, int>> E[300005];
vector<int> pick;
int solve(int x) {
  used[x] = true;
  int ret = 0;
  for (auto e : E[x]) {
    int y = e.first, z = e.second;
    if (!used[y]) {
      int v = solve(y);
      if (D[y] != -1 && D[y] != v) {
        pick.push_back(z);
        ret ^= 1;
      }
    }
  }
  return ret;
}
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  int root = 0;
  bool ones = false;
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &D[i]);
    if (D[i] == -1)
      root = i;
    else if (D[i] == 1)
      ones = !ones;
  }
  for (int i = 1; i <= M; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    E[u].push_back({v, i});
    E[v].push_back({u, i});
  }
  if (!root && ones) {
    printf("-1\n");
    return 0;
  }
  if (!root) root = 1;
  int v = solve(root);
  if (v != D[root] && D[root] != -1) assert(false);
  printf("%d\n", pick.size());
  for (int e : pick) printf("%d\n", e);
}
