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 parity[3000000];
int main() {
  int n, m;
  cin >> n >> m;
  int d[n];
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    parity[i] = 0;
  }
  pair<int, pair<int, int> > edges[m];
  int maxedge[n];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    edges[i] = pair<int, pair<int, int> >(i, pair<int, int>(x, y));
    maxedge[x] = i;
    maxedge[y] = i;
  }
  vector<int> v;
  for (int i = 0; i < m; i++) {
    bool escolhe = false;
    int x, y;
    x = edges[i].second.first;
    y = edges[i].second.second;
    if (i != maxedge[x] && i != maxedge[y]) {
      if (d[x] != -1 && d[y] != -1) {
        if (parity[x] == d[x] & parity[y] == d[y]) {
          escolhe = false;
        }
      }
      if (d[x] == -1) {
        if (parity[y] != d[y]) {
          escolhe = true;
        }
      }
      if (d[y] == -1) {
        if (parity[x] != d[x]) {
          escolhe = true;
        }
      }
    }
    if (i == maxedge[x] && d[x] != -1) {
      if (i == maxedge[y] && d[y] != -1) {
        if (parity[x] != d[x] && parity[y] != d[y]) {
          escolhe = true;
        }
      } else {
        if (parity[x] == d[x]) {
          escolhe = false;
        }
      }
    }
    if (i == maxedge[y] && d[y] != -1) {
      if (parity[y] == d[y]) {
        escolhe = true;
      }
    }
    if (escolhe) {
      parity[x]++;
      parity[y]++;
      parity[x] %= 2;
      parity[y] %= 2;
      v.push_back(i + 1);
    }
  }
  bool b = true;
  for (int i = 0; i < n; i++) {
    if (parity[i] != d[i] && d[i] != -1) {
      b = false;
    }
  }
  if (b) {
    cout << v.size() << endl;
    for (int i = 0; i < v.size(); i++) {
      cout << v[i] << endl;
    }
  } else {
    cout << -1 << endl;
  }
  return 0;
}
