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 OO = 1e9;
const long long INF = 1e18;
const int irand(int lo, int hi) {
  return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
const long long lrand(long long lo, long long hi) {
  return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
const int N = 3e5 + 5;
int n, m;
int d[N];
bool required[N];
bool multi[N];
vector<pair<int, int> > lst[N];
bool use[N];
bool vis[N];
stack<int> stk;
bool fromtop = true;
int last = -1, lastlast;
void dfs(int now) {
  if (vis[now]) return;
  vis[now] = true;
  if (d[now] == 1) {
    if (last != -1) {
      d[now] = 0;
      d[last] = 0;
      while (!stk.empty()) {
        use[stk.top()] ^= 1;
        stk.pop();
      }
      last = -1;
    } else {
      last = now;
    }
    fromtop = true;
  }
  for (int i = 0; i < lst[now].size(); i++) {
    int e = lst[now][i].second;
    int to = lst[now][i].first;
    bool tmp = fromtop;
    fromtop = true;
    if (last != -1) {
      stk.push(e);
      lastlast = last;
    } else
      lastlast = -2;
    dfs(to);
    if (last == lastlast && fromtop) {
      stk.pop();
      fromtop = tmp;
    } else if (last != -1 && !fromtop) {
      stk.push(e);
    }
  }
  if (last == now) {
    fromtop = false;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cin >> n >> m;
  for (int i = 1; i <= n; i += 1) cin >> d[i];
  for (int i = 1; i <= n; i += 1)
    if (d[i] == 1)
      required[i] = true;
    else if (d[i] == -1)
      multi[i] = true;
  for (int i = 1; i <= m; i += 1) {
    int a, b;
    cin >> a >> b;
    lst[a].push_back(make_pair(b, i));
    lst[b].push_back(make_pair(a, i));
  }
  dfs(1);
  while (!stk.empty()) stk.pop();
  memset(vis, false, sizeof vis);
  last = -1;
  for (int i = 1; i <= n; i += 1)
    if (d[i] == -1) d[i] = 1;
  dfs(1);
  int cnt = 0;
  for (int i = 1; i <= n; i += 1)
    if (d[i] == 1 && required[i]) cnt++;
  assert(cnt <= 1);
  int dummy = -1;
  for (int i = 1; i <= m; i += 1) {
    if (multi[i] && d[i] == 0) {
      dummy = i;
    }
  }
  if (dummy != -1) {
    d[dummy] = 1;
    while (!stk.empty()) stk.pop();
    memset(vis, false, sizeof vis);
    last = -1;
    dfs(1);
  }
  bool rekt = false;
  for (int i = 1; i <= n; i += 1)
    if (d[i] == 1 && required[i]) rekt = true;
  if (rekt)
    cout << -1 << endl;
  else {
    int cnt = 0;
    for (int i = 1; i <= m; i += 1)
      if (use[i]) cnt++;
    cout << cnt << endl;
    for (int i = 1; i <= n; i += 1)
      if (use[i]) cout << i << endl;
  }
  return 0;
}
