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;
int n, m;
vector<vector<int>> adj1;
vector<int> ord;
vector<int> d;
vector<bool> vis;
vector<int> p;
map<pair<int, int>, int> mp;
void dfs1(int second) {
  vis[second] = true;
  for (auto i : adj1[second]) {
    if (!vis[i]) {
      p[i] = second;
      dfs1(i);
    }
  }
  ord.push_back(second);
}
int main() {
  cin >> n >> m;
  d.assign(n, 0);
  vis.assign(n, 0);
  p.assign(n, -1);
  adj1.assign(n, vector<int>());
  int second = 0, cnt = 0;
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
    if (d[i] == 1) second++;
    if (d[i] == -1) cnt++;
  }
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj1[u].push_back(v);
    adj1[v].push_back(u);
    mp[{min(u, v), max(u, v)}] = i + 1;
  }
  if (second % 2 && !cnt) {
    cout << -1;
    return 0;
  }
  if (second % 2) {
    for (int i = 0; i < n; ++i) {
      if (d[i] == -1) {
        d[i] = 1;
        break;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (d[i] == -1) d[i] = 0;
  }
  dfs1(0);
  vector<int> res;
  for (int j = 0; j < n; ++j) {
    int i = ord[j];
    if (d[i] == 1) {
      res.push_back(mp[{min(i, p[i]), max(i, p[i])}]);
      d[p[i]] = 1 - d[p[i]];
    }
  }
  cout << res.size() << "\n";
  for (auto i : res) {
    cout << i << "\n";
  }
}
