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 + 77;
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];
set<pair<int, int> > g1[maxn], g2[maxn];
vector<pair<int, int> > a[maxn];
bool dfs1(int v, int an = -1) {
  if (d[v - 1] == 1 && an != -1) {
    d[v - 1] = 0;
    return 1;
  }
  for (set<pair<int, int> >::iterator it = g1[v].begin(); it != g1[v].end();) {
    int to = (*it).first, in = (*it).second;
    it++;
    g1[v].erase(make_pair(to, in));
    g1[to].erase(make_pair(v, in));
    if (dfs1(to, v)) {
      a[v].push_back(make_pair(to, in));
      return 1;
    }
  }
  return 0;
}
bool dfs2(int v, int an = -1) {
  if (d[v - 1] == -1 && an != -1) {
    d[v - 1] = 0;
    return 1;
  }
  for (set<pair<int, int> >::iterator it = g2[v].begin(); it != g2[v].end();) {
    int to = (*it).first, in = (*it).second;
    it++;
    g2[v].erase(make_pair(to, in));
    g2[to].erase(make_pair(v, in));
    if (dfs2(to, v)) {
      a[v].push_back(make_pair(to, in));
      return 1;
    }
  }
  return 0;
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> d[i];
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    g1[v].insert(make_pair(u, i));
    g1[u].insert(make_pair(v, i));
    g2[v].insert(make_pair(u, i));
    g2[u].insert(make_pair(v, i));
  }
  for (int i = 1; i <= n; i++) {
    if (d[i - 1] == 1) {
      d[i - 1] = 0;
      if (!dfs1(i)) d[i - 1] = 1;
    }
  }
  for (int i = 1; i <= n; i++)
    if (d[i - 1] == 1) {
      d[i - 1] = 0;
      if (!dfs2(i)) d[i - 1] = 1;
    }
  for (int i = 1; i <= n; i++) {
    if (d[i - 1] == 1) {
      cout << -1;
      return;
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) ans += a[i].size();
  cout << ans << "\n";
  for (int i = 1; i <= n; i++)
    for (pair<int, int> x : a[i]) cout << x.second + 1 << "\n";
}
int main() {
  srand(time(0));
  ios_base::sync_with_stdio(0);
  ;
  solve();
  return 0;
}
