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 MX = 2100006;
short d[MX];
int n, m;
vector<int> out;
int degnow[MX];
bool processed[MX];
map<int, int> a[MX];
bool vs[MX];
void egal(int x) {
  vs[x] = 1;
  for (auto it : a[x]) {
    int y = it.first;
    if (!vs[y]) {
      egal(y);
      if (degnow[y] ^ d[y]) {
        out.push_back(it.second);
        degnow[x] = 1 - degnow[x];
      }
    }
  }
}
int countt(int x) {
  int ans = d[x];
  vs[x] = true;
  for (auto it : a[x]) {
    int y = it.first;
    if (!vs[y]) {
      ans += countt(y);
      if (degnow[y] ^ d[y]) {
        out.push_back(it.second);
        degnow[x] = 1 - degnow[x];
      }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < (n); i++) {
    cin >> d[i];
  }
  for (int i = 0; i < (m); i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a[x][y] = i + 1;
    a[y][x] = i + 1;
  }
  for (int i = 0; i < (n); i++) {
    if (!vs[i] && d[i] == -1) {
      egal(i);
    }
  }
  for (int i = 0; i < (n); i++) {
    if (!vs[i]) {
      if (countt(i) % 2 != 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << out.size() << endl;
  for (auto x : out) {
    cout << x << " ";
  }
  cout << endl;
}
