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 MAX_N = 300001;
struct Triple {
  int x, y;
  bool z;
  Triple() {}
  Triple(int _x, int _y, bool _z) : x(_x), y(_y), z(_z) {}
};
int n, m;
int d[MAX_N];
bool used[MAX_N];
vector<Triple> v[MAX_N];
void read() {
  int x, y;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    v[x].push_back(Triple(y, i, 0));
    v[y].push_back(Triple(x, i, 0));
  }
}
int leftover;
void dfs(int ver, int edgeid1, int edgeid2, bool &state) {
  used[ver] = 1;
  if (d[ver] == 1) {
    state ^= true;
    leftover = ver;
  }
  for (int i = 0; i < v[ver].size(); i++)
    if (!used[v[ver][i].x]) {
      if (state) v[ver][i].z ^= true;
      dfs(v[ver][i].x, ver, i, state);
    }
  if (state && edgeid1 != -1) v[edgeid1][edgeid2].z ^= 1;
}
void cleanup(int ver, bool &reached) {
  if (ver == leftover) {
    reached = true;
    return;
  }
  used[ver] = 1;
  for (int i = 0; i < v[ver].size(); i++)
    if (!used[v[ver][i].x]) {
      cleanup(v[ver][i].x, reached);
      if (reached) {
        v[ver][i].z ^= true;
        return;
      }
    }
}
void fixLeftover(int ver, bool &state) {
  if (d[ver] == -1) {
    state = false;
    return;
  }
  used[ver] = 1;
  for (int i = 0; i < v[ver].size(); i++)
    if (!used[v[ver][i].x]) {
      fixLeftover(v[ver][i].x, state);
      if (!state) {
        v[ver][i].z ^= true;
        return;
      }
    }
}
int main() {
  read();
  bool state = false;
  dfs(1, -1, -1, state);
  if (state) {
    memset(used, 0, sizeof(used));
    bool reached = false;
    cleanup(1, reached);
    memset(used, 0, sizeof(used));
    fixLeftover(leftover, state);
  }
  if (!state) {
    int cnt = 0;
    for (int i = 1; i <= n; i++)
      for (int j = 0; j < v[i].size(); i++)
        if (v[i][j].z) cnt++;
    printf("%d\n", cnt);
    for (int i = 1; i <= n; i++)
      for (int j = 0; j < v[i].size(); i++)
        if (v[i][j].z) printf("%d\n", v[i][j].y);
  } else
    printf("-1\n");
}
