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, d[300010], u, v, deg[300010], ck[300010];
set<int> st, stt;
vector<int> edge[300010];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", d + i);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &u, &v);
    if (d[u] == -1 && d[v] == -1) {
      st.insert(i);
      ck[u] = ck[v] = 1;
    } else {
      if (d[u] != -1 && d[v] != -1) {
        if (d[u] == 1 && d[v] == 1) {
          d[u] = 0;
          d[v] = 0;
          ck[u] = ck[v] = 1;
          stt.insert(i);
        } else {
          st.insert(i);
        }
      } else {
        if (d[u] == -1) {
          if (d[v] == 1) {
            d[v] = 0;
            stt.insert(i);
          } else {
            st.insert(i);
          }
        } else {
          if (d[u] == 1) {
            d[u] = 0;
            stt.insert(i);
          } else {
            st.insert(i);
          }
        }
      }
    }
  }
  bool f = false;
  for (int i = 1; i <= n; i++) {
    if (d[i] == 1) f = true;
  }
  if (f) {
    printf("-1\n");
  } else {
    printf("%d\n", stt.size());
    for (auto it = stt.begin(); it != stt.end(); ++it) {
      printf("%d\n", *it);
    }
  }
}
