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 N = 300005;
int n, m, c[N], d[N], x[N], y[N];
vector<pair<int, int>> e[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &d[i]);
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &x[i], &y[i]);
    e[x[i]].push_back({y[i], i});
    e[y[i]].push_back({x[i], i});
  }
  set<int> ans;
  for (int i = 1; i <= n; ++i) {
    if (~d[i]) {
      if (c[i] != d[i]) {
        bool flag = 0;
        for (auto x : e[i]) {
          int u = x.first, id = x.second;
          if (d[u] == -1 || u > i) {
            ans.insert(id);
            c[u] ^= 1;
            flag = 1;
            break;
          }
        }
        if (!flag) {
          puts("-1");
          return 0;
        }
      }
    }
  }
  printf("%d\n", (int)ans.size());
  for (auto x : ans) {
    printf("%d\n", x);
  }
  return 0;
}
