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 oo = 0x3f3f3f3f;
const int MAXN = 1000100;
bool vis[300010], choose[300010], nn[300010];
int d[300010];
vector<int> edge[300010];
map<pair<int, int>, int> ma;
int sum = 0;
void dfs(int u, int f) {
  if (vis[u]) return;
  vis[u] = true;
  for (int i = 0; i < edge[u].size(); ++i) {
    int v = edge[u][i];
    if (v == f) continue;
    dfs(v, u);
    if (d[v] != -1) {
      if (nn[v] % 2 != d[v]) {
        int t1 = min(u, v), t2 = max(u, v);
        choose[ma[make_pair(u, v)]] = true;
        ++sum;
        ++nn[u];
        ++nn[v];
      }
    }
  }
}
int main() {
  int n, m, u, v;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &d[i]);
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
    if (u > v) swap(u, v);
    ma[make_pair(u, v)] = i + 1;
  }
  for (int i = 1; i <= n; ++i) {
    if (!vis[i] && d[i] == -1) dfs(i, 0);
  }
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      dfs(i, 0);
      if ((nn[i] % 2) != d[i]) puts("-1"), exit(0);
    }
  }
  cout << sum << endl;
  for (int i = 1; i <= m; ++i) {
    if (choose[i] == true) printf("%d\n", i);
  }
  return 0;
}
