#include <bits/stdc++.h>
using namespace std;
void ga(int N, int *A) {
  for (int i(0); i < N; i++) scanf("%d", A + i);
}
vector<int> g[(222222)];
char c;
int N, M, B[(222222)], E[(222222)], C[(222222)], a, b, Z[(222222)];
vector<int> o, O, U[2], V[2];
bool dfs(int u, int c) {
  if (~Z[u]) return Z[u] == c;
  U[Z[u] = c].push_back(u);
  for (auto &h : g[u])
    if (!dfs(h, !c)) return 0;
  return 1;
}
bool go(vector<int> &o) {
  for (auto &h : g) h.clear();
  (memset(Z, -1, sizeof(Z)));
  for (int i(0); i < N; i++)
    g[i * 2].push_back(i * 2 | 1), g[i * 2 | 1].push_back(i * 2);
  for (int i(0); i < M; i++)
    if (C[i])
      g[B[i] * 2].push_back(E[i] * 2), g[E[i] * 2].push_back(B[i] * 2);
    else
      g[B[i] * 2].push_back(E[i] * 2 | 1), g[E[i] * 2 | 1].push_back(B[i] * 2),
          g[B[i] * 2 | 1].push_back(E[i] * 2),
          g[E[i] * 2].push_back(B[i] * 2 | 1);
  for (int i(0); i < N; i++)
    if (!~Z[2 * i]) {
      for (int j(0); j < 2; j++) U[j].clear(), V[j].clear();
      if (!dfs(2 * i, 0)) return 0;
      for (int j(0); j < 2; j++)
        for (auto &h : U[j])
          if (!(h & 1)) V[j].push_back(h);
      if (V->size() > V[1].size()) swap(V[0], V[1]);
      for (auto &h : V[0]) o.push_back(h / 2);
    }
  return 1;
}
int main(void) {
  scanf("%d%d", &N, &M);
  for (int i(0); i < M; i++)
    scanf("%d%d %c", B + i, E + i, &c), --B[i], --E[i], C[i] = c == 66;
  a = go(o);
  for (int i(0); i < M; i++) C[i] ^= 1;
  b = go(O);
  if (!a && !b) return puts("-1"), 0;
  if (!a || (b && O.size() < o.size())) o = O;
  printf("%lu\n", o.size());
  for (int i(0); i < int(o.size()); i++)
    printf("%d%c", o[i] + 1, i + 1 == int(o.size()) ? 10 : 32);
  return 0;
}
