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;
inline long long getnum() {
  char c = getchar();
  long long num, sign = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (num = 0; c >= '0' && c <= '9';) {
    c -= '0';
    num = num * 10 + c;
    c = getchar();
  }
  return num * sign;
}
multiset<int> Set[300004];
vector<pair<int, int>> ans;
int A[300004], pos = 1;
map<pair<int, int>, set<int>> Map;
void dfs(int n, int p, int xr) {
  if (A[n] != -1)
    A[n] ^= xr;
  else
    A[n] = 0;
  if (A[n] == 0) return;
  if (Set[n].size() == 0) return;
  int x = *Set[n].begin();
  A[n] = 0;
  Set[x].erase(n);
  Set[n].erase(x);
  ans.push_back({x, n});
  dfs(x, n, 1);
}
int main() {
  int n = getnum(), m = getnum();
  for (int i = 1; i <= n; i++) A[i] = getnum();
  for (int i = 1; i <= m; i++) {
    int x = getnum(), y = getnum();
    Set[x].insert(y);
    Set[y].insert(x);
    Map[{x, y}].insert(i);
    Map[{y, x}].insert(i);
  }
  for (int i = 1; i <= n; i++)
    if (A[i] == 1) dfs(i, -1, 0);
  for (int i = 1; i <= n; i++)
    if (A[i] == 1) pos = 0;
  if (pos) {
    printf("%d\n", ans.size());
    for (int i = 0; i < ans.size(); i++) {
      printf("%d\n", *Map[{ans[i].first, ans[i].second}].begin());
      Map[{ans[i].first, ans[i].second}].erase(
          Map[{ans[i].first, ans[i].second}].begin());
    }
  } else {
    puts("-1");
  }
}
