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;
const int MN = 300005, inf = 1000000005, MOD = 1000000007;
const long long INF = 1000000000000000005LL;
int chce[MN], used[MN], stop[MN], D[MN];
vector<int> ans;
pair<int, int> E[MN];
vector<pair<int, int> > G[MN];
void nope() {
  printf("-1");
  exit(0);
}
int dfs(int x) {
  used[x] = 1;
  for (auto v : G[x])
    if (!used[v.first]) {
      int chce = dfs(v.first);
      if (chce) {
        stop[x] ^= 1;
        ans.push_back(v.second);
      }
    }
  if (D[x] == -1 || D[x] == stop[x]) return 0;
  return 1;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &D[i]);
  for (int i = 1; i <= m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    E[i] = {a, b};
    G[a].push_back({b, i});
    G[b].push_back({a, i});
  }
  for (int i = 1; i <= n; ++i)
    if (!used[i] && D[i] == -1) dfs(i);
  for (int i = 1; i <= n; ++i)
    if (!used[i])
      if (dfs(i)) nope();
  int s = ans.size();
  printf("%d\n", s);
  for (auto x : ans) printf("%d\n", x);
  return 0;
}
