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 N = 300005;
int d[N];
vector<pair<int, int>> g[N];
set<int> ans;
int vis[N];
void f(int u) {
  vis[u] = 1;
  int v, w;
  for (auto x : g[u]) {
    tie(v, w) = x;
    if (vis[v]) continue;
    f(v);
    if (d[v] == 1) {
      ans.insert(w);
      if (d[u] == 1)
        d[u] = 0;
      else if (d[u] == 0)
        d[u] = 1;
    }
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", d + i);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    g[a].emplace_back(b, i);
    g[b].emplace_back(a, i);
  }
  int st = 1;
  for (int i = 1; i <= n; i++)
    if (d[i] == -1) {
      st = i;
      break;
    }
  f(st);
  if (d[st] == 1) return printf("-1\n"), 0;
  printf("%d\n", (int)ans.size());
  for (int x : ans) printf("%d ", x + 1);
  printf("\n");
}
