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 = 300010, LN = 19;
vector<pair<int, int>> adj[N];
int d[N];
int p[LN][N];
int vis[N], dep[N];
void prep(int u, int d = 0) {
  vis[u] = 1;
  dep[u] = d;
  for (auto& e : adj[u]) {
    int v, id;
    tie(v, id) = e;
    if (!vis[v]) {
      p[0][v] = u;
      prep(v, d + 1);
    }
  }
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int diff = dep[u] - dep[v];
  for (int i = 0; i < LN; i++) {
    if ((diff >> i) & 1) {
      u = p[i][u];
    }
  }
  if (u == v) return u;
  for (int i = LN - 1; i >= 0; i--) {
    if (p[i][u] != p[i][v]) {
      u = p[i][u];
      v = p[i][v];
    }
  }
  return p[0][u];
}
int acc[N];
vector<int> eds;
int dfs(int u) {
  int ans = 0;
  for (auto& e : adj[u]) {
    int v, id;
    tie(v, id) = e;
    if (p[0][v] == u) {
      int t = dfs(v);
      if (t & 1) eds.push_back(id);
      ans += t;
    }
  }
  return ans + acc[u];
}
int main() {
  ios::sync_with_stdio(false);
  memset(p, -1, sizeof p);
  int n, m;
  cin >> n >> m;
  vector<int> path;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    if (d[i] == 1) path.push_back(i);
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].emplace_back(v, i);
    adj[v].emplace_back(u, i);
  }
  if ((path.size() % 2) == 1) {
    for (int i = 1; i <= n; i++) {
      if (d[i] == -1) {
        path.push_back(i);
        break;
      }
    }
  }
  if ((path.size() % 2) == 1) {
    cout << -1 << endl;
    return 0;
  }
  prep(1);
  for (int i = 1; i < LN; i++) {
    for (int j = 1; j <= n; j++) {
      if (p[i - 1][j] != -1) {
        p[i][j] = p[i - 1][p[i - 1][j]];
      }
    }
  }
  for (int i = 0; i < path.size(); i += 2) {
    int u = path[i], v = path[i + 1];
    int a = lca(u, v);
    acc[u] += 1;
    acc[v] += 1;
    acc[a] -= 2;
  }
  int t = dfs(1);
  cout << eds.size() << endl;
  for (int x : eds) {
    cout << x << "\n";
  }
  return 0;
}
