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;
map<pair<int, int>, int> ednum;
vector<int> gr[300500];
int d[300500];
int clr[300500];
vector<int> res;
void dfs(int u, int p) {
  clr[u] = 1;
  for (auto v : gr[u]) {
    if (!clr[v]) {
      dfs(v, u);
    }
  }
  if (d[u] == 1) {
    res.push_back(ednum[{u, p}]);
    d[p] = 1 - d[p];
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int sum = 0;
  int fl = 0;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    if (d[i] > -1) {
      sum += d[i];
    } else
      fl++;
  }
  if (sum % 2 && !fl) {
    cout << -1;
    return 0;
  }
  if (sum % 2) {
    fl = 0;
    for (int i = 1; i <= n; i++) {
      if (d[i] == -1) {
        if (!fl) {
          fl++;
          d[i] = 1;
        } else {
          d[i] = 0;
        }
      }
    }
  } else {
    fl = 0;
    for (int i = 1; i <= n; i++) {
      if (d[i] == -1) {
        if (!fl) {
          fl++;
          d[i] = 0;
        } else {
          d[i] = 0;
        }
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    gr[a].push_back(b);
    gr[b].push_back(a);
    ednum[{a, b}] = i;
    ednum[{b, a}] = i;
  }
  dfs(1, 0);
  cout << res.size() << endl;
  for (auto x : res) {
    cout << x << ' ';
  }
  return 0;
}
