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;
int d[303030];
vector<pair<int, int> > v[303030];
int use[303030];
int vis[303030];
int dfs(int x, int isroot) {
  int c = 0;
  vis[x] = 1;
  for (auto p : v[x]) {
    if (vis[p.first]) continue;
    if (dfs(p.first, 0)) {
      c++;
      use[p.second] = 1;
    }
  }
  if (isroot) {
    if (d[x] != -1 && c % 2 != d[x])
      return 0;
    else
      return 1;
  }
  if (c % 2 == d[x])
    return 0;
  else
    return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  int root = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    if (d[i] == -1) root = i;
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    v[a].emplace_back(b, i);
    v[b].emplace_back(a, i);
  }
  if (dfs(root, 1)) {
    int k = 0;
    for (int i = 1; i <= m; i++) {
      if (use[i] != 0) k++;
    }
    printf("%d\n", k);
    for (int i = 1; i <= m; i++) {
      if (use[i] != 0) {
        printf("%d\n", i);
      }
    }
  } else {
    printf("-1\n");
  }
}
