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;
int a[300300];
int v[303003];
vector<pair<int, int> > p[300300];
bool dfs(int x) {
  while (!p[x].empty()) {
    pair<int, int> t = p[x].back();
    p[x].pop_back();
    if (v[t.second]) continue;
    v[t.second] = 1;
    if (a[t.first] == 1) {
      a[t.first] = 0;
      return 1;
    }
    if (a[t.first] == -1) {
      return 1;
    }
    if (dfs(t.first)) return 1;
    v[t.second] = 0;
  }
  return 0;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int x, y;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    p[x].push_back(make_pair(y, i));
    p[y].push_back(make_pair(x, i));
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      if (dfs(i)) {
        a[i] = 0;
      } else {
        cout << -1;
        return 0;
      }
    }
  }
  int r = 0;
  for (int i = 0; i < m; i++) {
    if (v[i] == 1) r++;
  }
  cout << r << endl;
  for (int i = 0; i < m; i++) {
    if (v[i] == 1) printf("%d ", i + 1);
  }
  return 0;
}
