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 inf = 1e9 + 7, maxn = 3e5 + 500;
vector<pair<int, int> > v[maxn];
bool visited[maxn];
int par[maxn], d[maxn], deg[maxn];
set<int> s;
void dfs(int u, int p) {
  visited[u] = 1;
  par[u] = p;
  int idx = 0;
  for (int i = 0; i < v[u].size(); i++) {
    int w = v[u][i].first;
    if (!visited[w]) dfs(w, u);
    if (w == p) idx = v[u][i].second;
  }
  if (d[u] == -1) return;
  if (deg[u] % 2 != d[u]) {
    deg[p]++;
    s.insert(idx);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m, cntt = 0, cnt = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    if (d[i] == 1) cnt++;
    if (d[i] == -1) cntt++;
  }
  for (int i = 1; i <= m; i++) {
    int u, w;
    cin >> u >> w;
    v[u].push_back(make_pair(w, i));
    v[w].push_back(make_pair(u, i));
  }
  if (cnt % 2 == 1 and cntt == 0) return cout << -1 << endl, 0;
  if (cnt % 2 == 1) {
    for (int i = 1; i <= n; i++) {
      if (d[i] == -1) {
        d[i] = 1;
        break;
      }
    }
  }
  for (int i = 1; i <= n; i++)
    if (d[i] == -1) d[i] = 0;
  dfs(1, -1);
  cout << s.size() << endl;
  for (auto it : s) cout << it << " ";
}
