#include <bits/stdc++.h>
using namespace std;
static int N, M;
static vector<vector<pair<bool, int>>> adj;
static vector<int> sides[2];
static vector<int> visited;
static vector<int> solution;
bool dfs(int i, int side) {
  if (visited[i] != -1) {
    return visited[i] == side;
  }
  visited[i] = side;
  sides[side].push_back(i);
  for (pair<bool, int> col_j : adj[i]) {
    if (!dfs(col_j.second, side ^ col_j.first)) return false;
  }
  return true;
}
bool solve() {
  solution.clear();
  visited = vector<int>(N, -1);
  for (int i = 0; i < N; ++i) {
    if (visited[i] == -1) {
      sides[0].clear();
      sides[1].clear();
      if (!dfs(i, 0)) return false;
      if (sides[0].size() > sides[1].size()) sides[0].swap(sides[1]);
      for (int i : sides[0]) {
        solution.push_back(i);
      }
    }
  }
  return true;
}
void output(const vector<int>& sol) {
  cout << sol.size() << '\n';
  for (int i = 0; i < sol.size(); ++i) {
    if (i > 0) cout << ' ';
    cout << sol[i] + 1;
  }
  cout << '\n';
}
int main() {
  cin >> N >> M;
  adj.resize(N);
  for (int m = int(0); m < int(M); ++m) {
    int i, j;
    string s;
    cin >> i >> j >> s;
    assert(s == "R" || s == "B");
    bool col = (s == "R");
    adj[i - 1].push_back({col, j - 1});
    adj[j - 1].push_back({col, i - 1});
  }
  bool a = solve();
  vector<int> sol1 = solution;
  for (int i = int(0); i < int(N); ++i)
    for (int j = int(0); j < int(adj[i].size()); ++j) adj[i][j].first ^= 1;
  bool b = solve();
  vector<int> sol2 = solution;
  if (a && (!b || sol1.size() <= sol2.size())) {
    output(sol1);
  } else if (b) {
    output(sol2);
  } else {
    cout << -1 << '\n';
  }
}
