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 long long INF = 1e18;
const long long mod = 1e9 + 7;
const int N = 3e5 + 10;
int d[N];
int deg[N];
vector<pair<int, int> > edges[N];
bool taken[N];
bool vis[N];
int par[N];
void dfs(int s, int p, int e) {
  par[s] = p;
  if (p) deg[s]++;
  for (int i = 0; i < (int)edges[s].size(); i++) {
    if (edges[s][i].first == p or vis[edges[s][i].first]) continue;
    vis[edges[s][i].first] = true;
    deg[s]++;
    dfs(edges[s][i].first, s, edges[s][i].second);
  }
  if (p and d[s] != -1 and (deg[s] % 2) != d[s]) {
    taken[e] = false;
    deg[p]--;
  } else {
    taken[e] = true;
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  int flag = 0;
  memset(deg, 0, sizeof(deg));
  memset(taken, 0, sizeof(taken));
  memset(vis, 0, sizeof(vis));
  bool already = true;
  for (int i = 1; i <= n; ++i) {
    edges[i].clear();
    scanf("%d", &d[i]);
    if (d[i] == -1) flag = i;
    if (m == 0 and d[i] == 1) already = false;
  }
  if (already == false) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    edges[u].push_back(make_pair(v, i));
    edges[v].push_back(make_pair(u, i));
  }
  int root;
  if (flag)
    root = flag;
  else
    root = 1;
  vis[root] = true;
  dfs(root, 0, 0);
  if (d[root] == -1 or deg[root] == d[root]) {
    int cnt = 0;
    for (int i = 1; i <= m; ++i)
      if (taken[i]) cnt++;
    cout << cnt << endl;
    for (int i = 1; i <= m; ++i)
      if (taken[i]) printf("%d\n", i);
  } else
    cout << "-1" << endl;
  return 0;
}
