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 INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
const double eps = 1e-10;
const int N = 3e5 + 5;
int n, m, d[N];
vector<pair<int, int> > g[N];
vector<int> vec;
bool vis[N];
void dfs(int u) {
  vis[u] = true;
  for (auto &e : g[u]) {
    int &v = e.first;
    if (vis[v]) continue;
    dfs(v);
    if (d[v] == 1) {
      if (~d[u]) d[u] ^= 1;
      d[v] = 0, vec.push_back(e.second);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  int s = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", d + i);
    if (d[i] == -1) s = i;
  }
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d %d", &u, &v);
    g[u].push_back(pair<int, int>(v, i));
    g[v].push_back(pair<int, int>(u, i));
  }
  dfs(s);
  if (~d[s] && d[s]) {
    puts("-1");
    return 0;
  }
  printf("%d\n", vec.size());
  for (int id : vec) printf("%d\n", id);
  return 0;
}
