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>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
void itval(istream_iterator<string> it) {}
template <typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  itval(++it, args...);
}
const long long int MOD = 1e9 + 7;
template <typename T>
inline void print(T x) {
  cout << x << "\n";
}
template <typename T>
inline void printvec(T x) {
  for (auto a : x) cout << a << ' ';
  cout << '\n';
}
struct custom {
  bool operator()(const pair<int, pair<int, int> > &p1,
                  const pair<int, pair<int, int> > &p2) const {
    if (p1.first == p2.first) return p1.second.first > p2.second.first;
    return p1.first > p2.first;
  }
};
long long int get_pow(long long int a, long long int b, long long int M = MOD) {
  long long int res = 1;
  while (b) {
    if (b & 1) res = (res * a) % M;
    a = (a * a) % M;
    b >>= 1;
  }
  return res;
}
const long long int N = 3e5 + 5, inf = 2e18;
std::vector<pair<int, int> > adj[N];
int par[N], d[N];
set<int> ans;
bool vis[N];
void dfs(int s, int p, int id) {
  vis[s] = 1;
  for (auto x : adj[s]) {
    if (!vis[x.first]) dfs(x.first, s, x.second);
  }
  if (d[s] != -1 and d[s] != par[s]) {
    par[p] ^= 1;
    ans.insert(id);
  }
}
void solve() {
  int n, m, x, y;
  cin >> n >> m;
  int cnt = 0, root = 1;
  for (long long int i = (long long int)1; i < (long long int)(n + 1); i++) {
    cin >> d[i];
    if (d[i] == -1) {
      cnt++;
      root = i;
    }
  }
  for (long long int i = (long long int)1; i < (long long int)(m + 1); i++) {
    cin >> x >> y;
    adj[x].push_back({y, i});
    adj[y].push_back({x, i});
  }
  dfs(root, 0, 0);
  if (d[root] == -1 or par[0] == 0) {
    cout << ans.size() << '\n';
    printvec(ans);
  } else
    cout << -1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test = 1;
  clock_t z = clock();
  for (long long int tes = (long long int)0; tes < (long long int)(test);
       tes++) {
    solve();
  }
  fprintf(stderr, "Total Time:%.4f\n", (double)(clock() - z) / CLOCKS_PER_SEC),
      fflush(stderr);
  return 0;
}
