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>
#pragma comment(linker, "/STACK:1073741824")
#pragma warning(disable : 4996)
using namespace std;
const int MAXN = 3e5 + 100;
bool used[MAXN];
vector<pair<int, int>> v[MAXN];
vector<int> rd;
int d[MAXN];
int n, m, s = 0;
vector<int> *dfs(int node) {
  used[node] = 1;
  vector<int> *last = nullptr;
  for (auto p : v[node]) {
    int to = p.first, nn = p.second;
    if (!used[to]) {
      vector<int> *ret = dfs(to);
      if (ret != nullptr) {
        ret->push_back(nn);
        if (last == nullptr)
          last = ret;
        else {
          rd.insert(rd.end(), (*last).begin(), (*last).end());
          rd.insert(rd.end(), (*ret).begin(), (*ret).end());
        }
      }
    }
  }
  if (last != nullptr) {
    if (d[node] == 1 || s & 1 && d[node] == -1) {
      rd.insert(rd.end(), (*last).begin(), (*last).end());
      if (d[node] == -1) s--;
      return nullptr;
    } else
      return last;
  } else if (s & 1 && d[node] == -1 || d[node] == 1) {
    if (d[node] == -1) s--;
    return new vector<int>();
  }
  return nullptr;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &d[i]);
    if (d[i] == 1) s += d[i];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    v[a].push_back({b, i});
    v[b].push_back({a, i});
  }
  vector<int> *ret = dfs(0);
  if (ret != nullptr) {
    printf("-1");
    return 0;
  }
  printf("%d\n", rd.size());
  for (int i : rd) printf("%d\n", i + 1);
  return 0;
}
