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 maxi = 2e6 + 10;
pair<int, int> a[maxi];
int n, m;
int d[maxi];
vector<int> v[maxi];
int used[maxi];
int res;
int cnt[maxi];
int counter[maxi], counter1[maxi];
int main() {
  cin >> n >> m;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    if (d[i] >= 0) sum ^= d[i];
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a[i].first, &a[i].second);
    counter1[a[i].first]++;
    counter1[a[i].second]++;
  }
  for (int i = 1; i <= n; i++)
    if (d[i] == -1)
      if (sum) {
        d[i] = 1;
        sum ^= 1;
      } else
        d[i] = 0;
  if (sum) return !printf("-1\n");
  for (int j = 1; j <= 20; j++) {
    for (int i = 1; i <= n; i++) counter[i] = counter1[i];
    for (int i = 1; i <= m; i++) {
      if ((cnt[a[i].first] != d[a[i].first] &&
           cnt[a[i].second] != d[a[i].second]) ||
          (cnt[a[i].first] != d[a[i].first] &&
           counter[a[i].first] <= counter[a[i].second]) ||
          (cnt[a[i].second] != d[a[i].second] &&
           counter[a[i].second] <= counter[a[i].first])) {
        cnt[a[i].first] ^= 1;
        cnt[a[i].second] ^= 1;
        used[i] ^= 1;
        if (!used[i])
          res--;
        else
          res++;
      }
      counter[a[i].first]--;
      counter[a[i].second]--;
    }
  }
  cout << res << endl;
  for (int i = 1; i <= m; i++)
    if (used[i]) printf("%d ", i);
  return 0;
}
