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;
string itosm(long long x) {
  if (x == 0) return "0";
  string ans = "";
  while (x > 0) {
    ans += ((x % 10) + '0');
    x /= 10;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
long long stoim(string str) {
  long long ans = 0;
  long long k = 1;
  for (int i = str.length() - 1; i >= 0; i--) {
    ans += (str[i] - '0') * k;
    k *= 10;
  }
  return ans;
}
const long long infll = 1e18 + 3;
const int inf = 1009000999;
const double eps = 1e-7;
const int maxn = 3e5 + 777;
const int baseint = 1000200013;
const long long basell = 1e18 + 3;
const long double PI = acos(-1.0);
const long long mod = 1e9 + 7;
int d[maxn];
vector<pair<int, int> > g[maxn];
vector<pair<int, int> > ans[maxn];
bool used[maxn];
int n, m;
bool dfs(int v, int an = -1) {
  used[v] = 1;
  int st = 0;
  for (pair<int, int> to : g[v]) {
    if (an == to.first || used[to.first]) continue;
    if (dfs(to.first, v)) {
      st++;
      ans[v].push_back(to);
    }
  }
  if (d[v] != -1) {
    if (d[v] == 1 && (st & 1)) return 0;
    if (d[v] == 0 && st % 2 == 0) return 0;
    return 1;
  }
  return 0;
}
void solve() {
  cin >> n >> m;
  int st = -1;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    if (d[i] == -1 && st == -1) {
      st = i;
    } else if (d[i] == -1)
      d[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    g[v].push_back(make_pair(u, i + 1));
    g[u].push_back(make_pair(v, i + 1));
  }
  bool can = 1;
  if (st != -1) {
    dfs(st);
  } else if (m == n - 1) {
    can = !dfs(1);
  }
  int anss = 0;
  if (can) {
    for (int i = 1; i <= n; i++) anss += ans[i].size();
    cout << anss << "\n";
    for (int i = 1; i <= n; i++)
      for (pair<int, int> x : ans[i]) cout << x.second << "\n";
  } else {
    cout << -1;
  }
}
int main() {
  srand(time(0));
  ios_base::sync_with_stdio(0);
  ;
  solve();
  return 0;
}
