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;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
inline int readChar();
template <class T = int>
inline T readInt();
template <class T>
inline void writeInt(T x, char end = 0);
inline void writeChar(int x);
inline void writeWord(const char *s);
static const int buf_size = 4096;
inline int getChar() {
  static char buf[buf_size];
  static int len = 0, pos = 0;
  if (pos == len) {
    pos = 0, len = fread(buf, 1, buf_size, stdin);
  }
  if (pos == len) {
    return -1;
  }
  return buf[pos++];
}
inline int readChar() {
  int c = getChar();
  while (c <= 32) {
    c = getChar();
  }
  return c;
}
template <class T>
inline T readInt() {
  int s = 1, c = readChar();
  T x = 0;
  if (c == '-') s = -1, c = getChar();
  while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getChar();
  return s == 1 ? x : -x;
}
static int write_pos = 0;
static char write_buf[buf_size];
inline void writeChar(int x) {
  if (write_pos == buf_size)
    fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
  write_buf[write_pos++] = x;
}
template <class T>
inline void writeInt(T x, char end) {
  if (x < 0) writeChar('-'), x = -x;
  char s[24];
  int n = 0;
  while (x || !n) s[n++] = '0' + x % 10, x /= 10;
  while (n--) writeChar(s[n]);
  if (end) writeChar(end);
}
inline void writeWord(const char *s) {
  while (*s) writeChar(*s++);
}
struct Flusher {
  ~Flusher() {
    if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
  }
} flusher;
const int MAXN = 300001;
int n, m;
int st[MAXN];
int a[MAXN], b[MAXN];
bool used[MAXN];
vector<int> v[MAXN];
map<pair<int, int>, int> who;
vector<int> sons[MAXN];
int dp[MAXN][2];
int dp1[MAXN][2];
void dfs(int u) {
  used[u] = true;
  for (auto h : v[u]) {
    if (!used[h]) {
      dfs(h);
      sons[u].push_back(h);
    }
  }
  for (int i = 0; i <= (int)(sons[u]).size(); i++) {
    dp1[i][0] = 0;
    dp1[i][1] = 0;
  }
  dp1[0][0] = true;
  for (int i = 0; i < (int)(sons[u]).size(); i++) {
    if (dp[sons[u][i]][0]) {
      if (st[sons[u][i]] == -1 || st[sons[u][i]] == 0) {
        for (int t = 0; t < 2; t++) {
          chkmax(dp1[i + 1][t], dp1[i][t]);
        }
      } else {
        for (int t = 0; t < 2; t++) {
          chkmax(dp1[i + 1][t ^ 1], dp1[i][t]);
        }
      }
    }
    if (dp[sons[u][i]][1]) {
      if (st[sons[u][i]] == -1 || st[sons[u][i]] == 1) {
        for (int t = 0; t < 2; t++) {
          chkmax(dp1[i + 1][t], dp1[i][t]);
        }
      } else {
        for (int t = 0; t < 2; t++) {
          chkmax(dp1[i + 1][t ^ 1], dp1[i][t]);
        }
      }
    }
  }
  dp[u][0] = dp1[(int)(sons[u]).size()][0];
  dp[u][1] = dp1[(int)(sons[u]).size()][1];
}
int pr[MAXN][2];
int s[MAXN][2];
int needs[MAXN][2];
vector<int> ans;
void dfs1(int u, int id) {
  cout << u + 1 << ' ' << id << endl;
  used[u] = true;
  for (int i = 0; i <= (int)(sons[u]).size(); i++) {
    dp1[i][0] = 0;
    dp1[i][1] = 0;
  }
  dp1[0][0] = true;
  pr[0][0] = -1;
  for (int i = 0; i < (int)(sons[u]).size(); i++) {
    if (dp[sons[u][i]][0]) {
      if (st[sons[u][i]] == -1 || st[sons[u][i]] == 0) {
        for (int t = 0; t < 2; t++) {
          chkmax(dp1[i + 1][t], dp1[i][t]);
          if (dp1[i + 1][t] == dp1[i][t]) {
            pr[i + 1][t] = t;
            s[i + 1][t] = 0;
            needs[i + 1][t] = 0;
          }
        }
      } else {
        for (int t = 0; t < 2; t++) {
          chkmax(dp1[i + 1][t ^ 1], dp1[i][t]);
          if (dp1[i + 1][t ^ 1] == dp1[i][t]) {
            pr[i + 1][t ^ 1] = t;
            s[i + 1][t ^ 1] = 0;
            needs[i + 1][t] = 1;
          }
        }
      }
    }
    if (dp[sons[u][i]][1]) {
      if (st[sons[u][i]] == -1 || st[sons[u][i]] == 1) {
        for (int t = 0; t < 2; t++) {
          chkmax(dp1[i + 1][t], dp1[i][t]);
          if (dp1[i + 1][t] == dp1[i][t]) {
            pr[i + 1][t] = t;
            s[i + 1][t] = 1;
            needs[i + 1][t] = 0;
          }
        }
      } else {
        for (int t = 0; t < 2; t++) {
          chkmax(dp1[i + 1][t ^ 1], dp1[i][t]);
          if (dp1[i + 1][t ^ 1] == dp1[i][t]) {
            pr[i + 1][t ^ 1] = t;
            s[i + 1][t ^ 1] = 1;
            needs[i + 1][t] = 1;
          }
        }
      }
    }
  }
  int cur = (int)(sons[u]).size();
  int t = id;
  vector<int> ids, need;
  while (pr[cur][t] != -1) {
    ids.push_back(s[cur][t]);
    need.push_back(needs[cur][t]);
    t = pr[cur][t];
    cur--;
  }
  reverse((ids).begin(), (ids).end());
  reverse((need).begin(), (need).end());
  for (int i = 0; i < (int)(sons[u]).size(); i++) {
    int h = sons[u][i];
    dfs1(h, ids[i]);
    if (need[i]) {
      ans.push_back(who[make_pair(u, h)] + 1);
    }
  }
}
int main() {
  n = readInt(), m = readInt();
  for (int i = 0; i < n; i++) {
    st[i] = readInt();
  }
  for (int i = 0; i < m; i++) {
    a[i] = readInt(), b[i] = readInt();
    a[i]--, b[i]--;
    who[make_pair(a[i], b[i])] = i;
    who[make_pair(b[i], a[i])] = i;
  }
  for (int i = 0; i < m; i++) {
    v[a[i]].push_back(b[i]);
    v[b[i]].push_back(a[i]);
  }
  dfs(0);
  memset(used, 0, sizeof(used));
  if (st[0] == -1) {
    if (!dp[0][0] && !dp[0][1]) {
      writeInt(-1, '\n');
      return 0;
    }
    if (dp[0][0]) {
      dfs1(0, 0);
    } else {
      dfs1(0, 1);
    }
  } else {
    if (!dp[0][st[0]]) {
      writeInt(-1, '\n');
      return 0;
    }
    dfs1(0, st[0]);
  }
  writeInt((int)(ans).size(), '\n');
  for (auto x : ans) {
    writeInt(x, ' ');
  }
  writeChar('\n');
  return 0;
}
