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 maxn = 3e5 + 5;
int n, m, indeg[maxn], a[maxn], head[maxn], par[maxn], ecnt = 0, u, v;
vector<int> g[maxn];
bool vis[maxn];
struct node {
  int to, nxt;
} edge[maxn * 2];
vector<int> ans;
map<pair<int, int>, int> mp;
void add(int from, int to) {
  edge[ecnt].to = to;
  edge[ecnt].nxt = head[from];
  head[from] = ecnt++;
}
void dfs(int u, int fa) {
  if (vis[u]) return;
  vis[u] = 1;
  par[u] = fa;
  for (int i = head[u]; i != -1; i = edge[i].nxt) {
    int v = edge[i].to;
    dfs(v, u);
  }
  if (a[u] != -1) {
    if (fa != -1) {
      if (indeg[u] != a[u])
        a[u] ^= 1, a[par[u]] ^= 1, ans.push_back(mp[pair<int, int>(u, par[u])]);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  memset(head, -1, sizeof(head));
  int t = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &indeg[i]);
    if (indeg[i] == -1) t = i;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
    mp[pair<int, int>(u, v)] = i;
    mp[pair<int, int>(v, u)] = i;
  }
  dfs(t, -1);
  if (indeg[t] != -1 && a[t] != indeg[t])
    printf("-1\n");
  else {
    printf("%d\n", ans.size());
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++) printf("%d\n", ans[i]);
  }
  return 0;
}
