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 modu[300100];
vector<pair<int, int>> adj[300100];
vector<bool> eused[300100];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<pair<int, int>> edge;
  vector<int> minu;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &modu[i]);
    if (modu[i] == -1) minu.push_back(i);
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a].push_back({b, adj[b].size()});
    adj[b].push_back({a, adj[a].size() - 1});
    edge.push_back({a, b});
  }
  const int inf = 987654321;
  if (!minu.empty()) {
    vector<int> level(n + 10, inf);
    vector<int> parent(n + 10, -1);
    queue<int> q;
    for (auto i : minu) {
      level[i] = 0;
      q.push(i);
    }
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      for (auto next : adj[now]) {
        if (level[next.first] != inf) continue;
        parent[next.first] = now;
        level[next.first] = level[now] + 1;
        q.push(next.first);
      }
    }
    set<pair<int, int>> deleted;
    vector<pair<int, int>> cont;
    for (int i = 1; i <= n; i++) cont.push_back({-level[i], i});
    sort(cont.begin(), cont.end());
    for (int i = 0; i < cont.size(); i++) {
      int now = cont[i].second;
      if (adj[now].size() % 2 == modu[now] || modu[now] == -1) continue;
      deleted.insert({now, parent[now]});
      if (modu[parent[now]] == 1)
        modu[parent[now]] = 0;
      else if (modu[parent[now]] == 0)
        modu[parent[now]] = 1;
    }
    vector<int> left;
    for (int i = 0; i < edge.size(); i++) {
      if (deleted.find({edge[i].first, edge[i].second}) == deleted.end() &&
          deleted.find({edge[i].second, edge[i].first}) == deleted.end())
        left.push_back(i);
    }
    printf("%d\n", left.size());
    for (auto i : left) printf("%d\n", i + 1);
    return 0;
  } else {
    int s = 0;
    for (int i = 1; i <= n; i++)
      if (modu[i] == 1) s++;
    if (s % 2 == 1) {
      puts("-1");
      return 0;
    }
    vector<int> parent(n + 1, -1);
    vector<int> depth(n + 1, inf);
    vector<bool> visit(n + 1, false);
    vector<set<int>> child;
    child.resize(n + 1);
    set<pair<int, int>> edges;
    parent[1] = 1;
    queue<int> q;
    q.push(1);
    depth[1] = 1;
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      for (auto next : adj[now]) {
        if (parent[next.first] != -1) continue;
        parent[next.first] = now;
        q.push(next.first);
        depth[next.first] = depth[now] + 1;
        child[now].insert(next.first);
      }
    }
    vector<int> leaf;
    for (int i = 1; i <= n; i++)
      if (child[i].empty()) leaf.push_back(i);
    for (int i = 0; i < leaf.size(); i++) {
      int now = leaf[i];
      while (modu[now] == 0 && now != 1) {
        child[parent[now]].erase(now);
        now = parent[now];
      }
      if (now != 1) leaf[i] = now;
    }
    priority_queue<pair<int, int>> pq;
    for (int i = 1; i <= n; i++)
      if (modu[i] == 1) pq.push({depth[i], i});
    while (!pq.empty()) {
      auto now = pq.top().second;
      pq.pop();
      edges.insert({now, parent[now]});
      now = parent[now];
      if (pq.top().second == now)
        pq.pop();
      else
        pq.push({depth[now], now});
    }
    vector<int> left;
    for (int i = 0; i < edge.size(); i++) {
      if (edges.find({edge[i].first, edge[i].second}) != edges.end() ||
          edges.find({edge[i].second, edge[i].first}) != edges.end())
        left.push_back(i);
    }
    printf("%d\n", left.size());
    for (auto i : left) printf("%d\n", i + 1);
    return 0;
  }
}
