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 inf = 1e9 + 7;
const int N = 3e5 + 50;
struct Edge {
  int v, next;
  int idx;
} edge[N * 2];
int head[N];
inline void addEdge(int k, int u, int v, int idx) {
  edge[k].v = v;
  edge[k].next = head[u];
  edge[k].idx = idx;
  head[u] = k;
}
bool vis[N];
bool used[2 * N];
int val[N];
vector<int> vec;
bool flag = 0;
void dfs(int u, int p, int idx) {
  vis[u] = 1;
  if (val[u] == -1 && !flag) {
    flag = 1;
  }
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].v;
    if (!vis[v]) {
      if (!flag) {
        vec.push_back(i);
        dfs(v, u, i);
        if (!flag) {
          vec.pop_back();
        }
      } else {
        dfs(v, u, i);
      }
    }
  }
  if (val[u] == 1) {
    val[u] = 0;
    if (val[p] != -1) {
      val[p] ^= 1;
    }
    used[idx] ^= 1;
    used[idx ^ 1] ^= 1;
  }
}
void change() {
  for (int i : vec) {
    used[i] ^= 1;
    used[i ^ 1] ^= 1;
  }
}
void slove(int n, int m) {
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      vis[i] = 1;
      for (int j = head[i]; j != -1; j = edge[j].next) {
        int v = edge[j].v;
        if (!vis[v]) {
          vec.clear();
          vec.push_back(j);
          flag = 0;
          dfs(v, i, j);
        }
      }
      if (val[i] == 1) {
        if (!vec.empty() && val[edge[vec.back()].v] == -1) {
          change();
        } else {
          puts("-1");
          return;
        }
      }
    }
  }
  int num = 0;
  for (int i = 0; i < 2 * m; i += 2) {
    num += used[i];
  }
  printf("%d\n", num);
  for (int i = 0; i < 2 * m; i += 2) {
    if (used[i]) {
      --num;
      printf("%d%c", edge[i].idx, num == 0 ? '\n' : ' ');
    }
  }
}
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    fill(head, head + n + 1, -1);
    fill(vis, vis + n + 1, 0);
    fill(used, used + 2 * m + 1, 0);
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &val[i]);
    }
    for (int i = 0; i < m; ++i) {
      int u, v;
      scanf("%d%d", &u, &v);
      addEdge(2 * i, u, v, i + 1);
      addEdge(2 * i + 1, v, u, i + 1);
    }
    slove(n, m);
  }
  return 0;
}
