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 int read(int f = 1, int x = 0, char ch = ' ') {
  while (!isdigit(ch = getchar()))
    if (ch == '-') f = -1;
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f * x;
}
const int N = 2e5 + 5;
int n, m, c1, c2, d[N], vis[N], cnt, ans[N];
vector<pair<int, int> > e[N];
void dfs(int x) {
  vis[x] = 1;
  for (int i = 0; i < e[x].size(); ++i) {
    int y = e[x][i].first, z = e[x][i].second;
    if (vis[y]) continue;
    dfs(y);
    if (d[y] == 1) d[x] ^= 1, ans[++cnt] = z;
  }
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; ++i) d[i] = read(), c1 += d[i] == 1, c2 += d[i] == 2;
  if ((c1 & 1) && !c2) return puts("-1"), 0;
  if (c1 & 1)
    for (int i = 1; i <= n; ++i)
      if (d[i] == -1) d[i] = 1, i = n;
  for (int i = 1; i <= m; ++i) {
    int x = read(), y = read();
    e[x].emplace_back(y, i), e[y].emplace_back(x, i);
  }
  dfs(1), printf("%d\n", cnt);
  for (int i = 1; i <= cnt; ++i) printf("%d\n", ans[i]);
  return 0;
}
