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;
int n, m;
struct edge {
  int to, num, next;
  bool b;
};
int d[3 * 100000 + 5];
int g[3 * 100000 + 5];
edge e[3 * 100000 + 5];
bool vis[3 * 100000 + 5];
int cnt = 1;
inline void addedge(int from, int to, int num) {
  cnt++;
  e[cnt].to = to;
  e[cnt].num = num;
  e[cnt].b = 0;
  e[cnt].next = g[from];
  g[from] = cnt;
}
void dfs(int x) {
  for (int i = g[x]; i; i = e[i].next) {
    if (d[e[i].to] == 1) {
      d[e[i].to] = 0;
      if (d[x] != -1) d[x] = 1 - d[x];
      e[i].b = 1 - e[i].b;
    }
    if (!vis[e[i].to]) {
      vis[e[i].to] = 1;
      dfs(e[i].to);
    }
  }
  return;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int(i) = (1); (i) <= (n); (i)++) scanf("%d", &d[i]);
  int x, y;
  for (int(i) = (1); (i) <= (m); (i)++) {
    scanf("%d%d", &x, &y);
    addedge(x, y, i);
  }
  memset(vis, 0, sizeof(vis));
  int u = 1;
  for (int(i) = (1); (i) <= (n); (i)++)
    if (d[i] == -1) u = i;
  vis[u] = 1;
  dfs(u);
  for (int(i) = (1); (i) <= (n); (i)++)
    if (d[i] == 1) {
      cout << -1 << endl;
      return 0;
    }
  u = 0;
  for (int(i) = (2); (i) <= (cnt); (i)++)
    if (e[i].b == 1) u++;
  printf("%d\n", u);
  for (int(i) = (2); (i) <= (cnt); (i)++)
    if (e[i].b == 1) printf("%d ", i - 1);
  if (u) cout << endl;
  return 0;
}
