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 N = 3e5 + 7;
const int MX = 1e9 + 7;
const int INF = 1e9 + 9;
int res;
int n, m;
int d[N];
bool vis[N];
bool ans[N];
vector<pair<int, int> > G[N];
int dfs(int u) {
  int cur = 0;
  vis[u] = true;
  for (pair<int, int> v : G[u])
    if (!vis[v.first]) {
      int x = dfs(v.first);
      if (x & 1) {
        ans[v.second] = true;
        ++res;
        ++cur;
      }
    }
  if (d[u] == 1) ++cur;
  return cur;
}
int main() {
  int s = 0, d1 = 0;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &d[i]);
    if (d[i] == 1) ++s;
    if (d[i] == -1) d1 = i;
  }
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    G[u].push_back({v, i});
    G[v].push_back({u, i});
  }
  if ((s & 1) && d1 == 0) {
    puts("-1");
    return 0;
  }
  if (d1 == 0) d1 = 1;
  dfs(d1);
  printf("%d\n", res);
  for (int i = 1; i <= m; ++i)
    if (ans[i]) printf("%d\n", i);
  return 0;
}
