#include <bits/stdc++.h>
using namespace std;
const int MAXN = 621000;
int cnt, d[MAXN];
vector<int> g[MAXN];
set<int> g1[MAXN];
set<int> g2[MAXN];
bool flag = 0;
int p, n, m, sum;
int par[MAXN];
bool vis[MAXN];
int deg[MAXN];
bool error3;
map<pair<int, int>, int> edges;
void dfs(int u) {
  for (set<int>::iterator it = g1[u].begin(); it != g1[u].end(); it++) {
    dfs((*it));
  }
  if (par[u] != 0 && u != 1 && deg[u] % 2 != d[u]) {
    deg[u]--;
    deg[par[u]]--;
    g2[par[u]].insert(u);
    cnt--;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    if (d[i] == -1)
      flag = 1, p = i;
    else
      sum += d[i];
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    edges[{min(x, y), max(x, y)}] = i + 1;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  if (flag == 0 && sum % 2 == 1) {
    cout << "-1\n";
    return 0;
  }
  if (sum % 2 == 1) {
    for (int i = 1; i <= n; i++) {
      if (i == p) {
        d[i] = 1;
        continue;
      }
      if (d[i] == -1) {
        d[i] = 0;
      }
    }
  } else {
    for (int i = 1; i <= n; i++) {
      if (d[i] == -1) d[i] = 0;
    }
  }
  vis[1] = 1;
  queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int j = 0; j < g[u].size(); j++) {
      int v = g[u][j];
      if (vis[v] == 0) {
        deg[u]++;
        deg[v]++;
        par[v] = u;
        cnt++;
        g1[u].insert(v);
        vis[v] = 1;
        q.push(v);
      }
    }
  }
  dfs(1);
  if (error3) {
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (deg[i] % 2 != d[i]) {
      cout << "-1\n";
      return 0;
    }
  }
  set<int> ans;
  for (int i = 1; i <= n; i++) {
    for (set<int>::iterator it = g1[i].begin(); it != g1[i].end(); it++) {
      int u = i, v = (*it);
      if (u > v) swap(u, v);
      ans.insert(edges[{u, v}]);
    }
    for (set<int>::iterator it = g2[i].begin(); it != g2[i].end(); it++) {
      int u = i, v = (*it);
      if (u > v) swap(u, v);
      ans.erase(edges[{u, v}]);
    }
  }
  int cnt2 = 0;
  for (int i = 1; i <= n; i++) {
    cnt2 += g1[i].size();
    cnt2 -= g2[i].size();
  }
  if (ans.size() < cnt) {
    cout << "error1\n";
    return 0;
  }
  if (ans.size() > cnt) {
    cout << "error2\n";
    return 0;
  }
  cout << ans.size() << endl;
  for (set<int>::iterator it = ans.begin(); it != ans.end(); it++) {
    cout << (*it) << endl;
  }
  return 0;
}
