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;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 300000;
const int MAXM = 300000;
int n, m;
int want[MAXN];
vector<pair<int, int> > adj[MAXN];
bool been[MAXN];
int ans[MAXM], nans;
bool dfs(int at, int par) {
  been[at] = true;
  bool ret = want[at] == 1;
  for (int i = (0); i < (((int)(adj[at]).size())); ++i) {
    int to = adj[at][i].first;
    if (to == par || been[to]) continue;
    if (dfs(to, at)) {
      ans[nans++] = adj[at][i].second;
      ret = !ret;
    }
  }
  return par == -1 && want[at] == -1 ? false : ret;
}
void run() {
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (n); ++i) scanf("%d", &want[i]);
  for (int i = (0); i < (m); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    adj[a].push_back(make_pair(b, i)), adj[b].push_back(make_pair(a, i));
  }
  int rt = 0;
  for (int i = (0); i < (n); ++i)
    if (want[rt] != -1 && want[i] == -1) rt = i;
  for (int i = (0); i < (n); ++i) been[i] = false;
  nans = 0;
  if (dfs(rt, -1)) {
    printf("-1\n");
    return;
  }
  printf("%d\n", nans);
  for (int i = (0); i < (nans); ++i) printf("%d\n", ans[i] + 1);
}
int main() {
  run();
  return 0;
}
