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;
bool ok[300005], used[300005];
int vis[300005];
int a[300005], f[300005], s[300005];
vector<pair<int, int> > v[300005];
int pa[300005];
int n, m, gas;
int dfs(int k, int p = 0) {
  vis[k] = 1;
  for (int i = 0; i < v[k].size(); i++) {
    if (vis[v[k][i].first]) continue;
    pa[v[k][i].first] = k;
    int first = dfs(v[k][i].first, k);
    if (first == 1) {
      if (a[k] != -1) a[k] ^= 1;
      used[v[k][i].second] = 1;
    }
  }
  return a[k];
}
int dfs_1(int k, int p = 0) {
  vis[k] = 1;
  for (int i = 0; i < v[k].size(); i++) {
    if (vis[v[k][i].first]) continue;
    int first = dfs_1(v[k][i].first, k);
    if (first) {
      used[v[k][i].second] ^= 1;
      a[k] ^= 1;
    }
  }
  return a[k];
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", s + i, f + i);
    v[s[i]].push_back(pair<int, int>(f[i], i));
    v[f[i]].push_back(pair<int, int>(s[i], i));
  }
  for (int i = 1; i <= m; i++) {
    if (a[s[i]] == -1) ok[f[i]] = 1;
    if (a[f[i]] == -1) ok[s[i]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1 && !vis[i]) dfs(i);
  }
  bool flag = 0;
  for (int i = 1; i <= n && !flag; i++) {
    if (a[i] != -1 && !vis[i]) {
      flag = dfs_1(i);
    }
  }
  if (flag)
    puts("-1");
  else {
    for (int i = 1; i <= m; i++)
      if (used[i]) gas++;
    printf("%d\n", gas);
    for (int i = 1; i <= m; i++)
      if (used[i]) printf("%d\n", i);
  }
}
