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;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
int d[300125];
bool vis[300125];
vector<pair<int, int> > mp[300125];
vector<int> ans;
void dfs(int x, int pa) {
  vis[x] = 1;
  for (auto c : mp[x])
    if (c.first != pa && !vis[c.first]) {
      dfs(c.first, x);
      if (d[c.first] == 1) {
        ans.push_back(c.second);
        d[x] ^= 1;
      }
    }
}
void fmain(int tid) {
  scanf("%d%d", &n, &m);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d", d + i);
  int s = 0;
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    if (d[i] == 1) s++;
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    if (d[i] == -1) {
      if (s & 1) {
        s++;
        d[i] = 1;
      } else
        d[i] = 0;
    }
  if (s & 1) et();
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d%d", &u, &v);
    mp[u].push_back({v, i});
    mp[v].push_back({u, i});
  }
  dfs(1, 0);
  printf("%d\n", ans.size());
  for (int c : ans) printf("%d ", c);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
