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;
vector<pair<int, int> > Graph[300005], Tree[300005];
vector<int> V;
int D[300005], degree[300005];
bool Visited[300005];
void Construct_Tree(int root, int Parent, int index) {
  if (Visited[root] == 1) return;
  Visited[root] = 1;
  if (Parent != 0) {
    Tree[root].emplace_back(make_pair(Parent, index));
    Tree[Parent].emplace_back(make_pair(root, index));
    ++degree[Parent];
    ++degree[root];
  }
  for (int i = 0; i < int(Graph[root].size()); ++i)
    if (Visited[Graph[root][i].first] == 0)
      Construct_Tree(Graph[root][i].first, root, Graph[root][i].second);
}
void dfs(int root, int Parent, int index, int start) {
  for (int i = 0; i < int(Tree[root].size()); ++i)
    if (Tree[root][i].first != Parent)
      dfs(Tree[root][i].first, root, Tree[root][i].second, start);
  if (root == start) return;
  if (D[root] == 0) {
    if (degree[root] % 2 == 0)
      V.emplace_back(index);
    else {
      --degree[root];
      --degree[Parent];
    }
  } else if (D[root] == 1) {
    if (degree[root] % 2 == 1)
      V.emplace_back(index);
    else {
      --degree[root];
      --degree[Parent];
    }
  }
}
int main() {
  int Count = 0, Check = 0, N;
  int u, v, i, x = 0, m;
  scanf("%d%d", &N, &m);
  for (i = 1; i <= N; ++i) {
    scanf("%d", D + i);
    if (D[i] == 1)
      ++Count;
    else if (D[i] == -1) {
      Check = 1;
      x = i;
    }
  }
  for (i = 1; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    Graph[u].emplace_back(make_pair(v, i));
    Graph[v].emplace_back(make_pair(u, i));
  }
  if (Check == 0 && Count % 2 == 1) {
    puts("-1");
    return 0;
  }
  if (x == 0) x = 1;
  Construct_Tree(x, 0, 0);
  dfs(x, 0, 0, x);
  printf("%d\n", int(V.size()));
  for (i = 0; i < int(V.size()); ++i) printf("%d\n", V[i]);
  return 0;
}
