#include <bits/stdc++.h>
const int MAXN = 1e5 + 19;
int n, m;
std::vector<std::pair<int, char> > G[MAXN];
std::vector<int> s[3];
int vist[MAXN];
bool dfs(int node, int p, char T) {
  if (vist[node]) return vist[node] == p;
  vist[node] = p;
  s[p].push_back(node);
  for (auto e : G[node])
    if (!dfs(e.first, e.second == T ? p : p ^ 3, T)) return false;
  return true;
}
std::vector<int> solve(char T) {
  for (int i = 1; i <= n; ++i) vist[i] = 0;
  std::vector<int> ans;
  for (int i = 1; i <= n; ++i)
    if (vist[i] == 0) {
      s[1].clear(), s[2].clear();
      if (!dfs(i, 1, T)) return std::vector<int>(n + 1);
      if (s[1].size() < s[2].size())
        ans.insert(ans.end(), s[1].begin(), s[1].end());
      else
        ans.insert(ans.end(), s[2].begin(), s[2].end());
    }
  return ans;
}
int main() {
  std::scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    char c;
    std::scanf("%d%d %c", &u, &v, &c);
    G[u].emplace_back(v, c);
    G[v].emplace_back(u, c);
  }
  std::vector<int> x(solve('R')), y(solve('B'));
  if (y.size() < x.size()) std::swap(x, y);
  if (int(x.size()) == n + 1) {
    std::puts("-1");
    return 0;
  }
  std::printf("%d\n", int(x.size()));
  for (int i : x) std::printf("%d ", i);
  return 0;
}
