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;
typedef struct {
  int v;
  int id;
} Road;
Road now;
vector<Road> G[300005];
int val[300005], love[300005], use[300005];
int main(void) {
  int n, m, i, j, x, y, cnt, ok, ans;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &val[i]);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    now.v = y, now.id = i;
    G[x].push_back(now);
    now.v = x;
    G[y].push_back(now);
    if (val[x] == -1) love[y] = i;
    if (val[y] == -1) love[x] = i;
  }
  for (cnt = 1; cnt <= 1000; cnt++) {
    ok = 1;
    for (i = 1; i <= n; i++) {
      if (val[i] == 1) {
        if (love[i] != 0) {
          use[love[i]] ^= 1;
          break;
        }
        for (j = 0; j < G[i].size(); j++) {
          now = G[i][j];
          if (val[now.v] == 1) {
            use[now.id] ^= 1;
            val[now.v] = 0;
            break;
          } else if (val[now.v] == 0) {
            if (love[now.v] != 0) {
              use[love[now.v]] ^= 1;
              break;
            }
          }
        }
        if (j < G[i].size())
          val[i] = 0;
        else {
          ok = 0;
          break;
        }
      }
    }
    if (ok == 1) break;
  }
  if (ok == 0)
    printf("-1\n");
  else {
    ans = 0;
    for (i = 1; i <= m; i++) ans += use[i];
    printf("%d\n", ans);
    for (i = 1; i <= m; i++) {
      if (use[i]) printf("%d\n", i);
    }
  }
  return 0;
}
