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 N = 300007;
int d[N];
int vis[N];
int goodset[N];
vector<pair<int, int> > G[N];
stack<int> ans;
int dfs(int u, int tem) {
  vis[u] = 1;
  for (int i = 0; i < (G[u].size()); i++) {
    int v = G[u][i].first;
    int id = G[u][i].second;
    if (vis[v] == 1) continue;
    goodset[id] = 1;
    if (tem == 0 && d[v] == 1)
      return v;
    else if (tem == v)
      return v;
    vis[v] = 1;
    int res = dfs(v, tem);
    if (tem == 0 && res)
      return res;
    else if (tem == res)
      return res;
    goodset[id] = 0;
  }
  return 0;
}
int main(void) {
  int n, m;
  int cnt = 0;
  memset(vis, 0, sizeof(vis));
  memset(goodset, 0, sizeof(goodset));
  scanf("%d%d", &n, &m);
  for (int i = 1; i < (n + 1); i++) {
    scanf("%d", &d[i]);
    if (d[i] == 1) ans.push(i);
  }
  for (int i = 1; i < (m + 1); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(make_pair((v), (i)));
    G[v].push_back(make_pair((u), (i)));
  }
  int exce = 0;
  bool f = true;
  if (ans.size() % 2 == 1) {
    f = false;
    for (int i = 1; i < (n + 1); i++) {
      memset(vis, 0, sizeof(vis));
      if (d[i] == -1) {
        int tem = dfs(i, 0);
        if (tem) {
          f = true;
          exce = tem;
          break;
        }
      }
    }
  }
  if (f && ans.size() != 1)
    for (int i = 0; i < (ans.size()); i++) {
      int a, b;
      do {
        a = ans.top();
        ans.pop();
      } while (a == exce);
      do {
        b = ans.top();
        ans.pop();
      } while (b == exce);
      dfs(a, b);
    }
  if (f)
    for (int i = 1; i < (m + 1); i++)
      if (goodset[i]) cnt++;
  if (f) printf("%d\n", cnt);
  if (f)
    for (int i = 1; i < (m + 1); i++)
      if (goodset[i]) printf("%d\n", i);
  if (!f) printf("-1");
  return 0;
}
