#include <bits/stdc++.h>
using namespace std;
struct edge {
  int a, b;
  char color, now_color;
  edge(int a, int b, char c) {
    this->a = a;
    this->b = b;
    this->color = this->now_color = c;
  }
};
vector<int> gr[100005], all_comp, ans, best;
vector<int> ans_red, ans_blue;
vector<edge*> all;
int u[100005], cnt = 1;
void dfs(int v) {
  u[v] = cnt;
  for (int i = 0; i < gr[v].size(); i++) {
    int to = (all[gr[v][i]]->a == v ? all[gr[v][i]]->b : all[gr[v][i]]->a);
    if (u[to] != cnt) dfs(to);
  }
}
void dfs_prepare(int v) {
  u[v] = cnt;
  for (int i = 0; i < gr[v].size(); i++) {
    all[gr[v][i]]->now_color = all[gr[v][i]]->color;
    int to = (all[gr[v][i]]->a == v ? all[gr[v][i]]->b : all[gr[v][i]]->a);
    if (u[to] != cnt) dfs_prepare(to);
  }
}
void dfs_draw(int v, char c, bool need) {
  u[v] = cnt;
  if (need == true) {
    for (int i = 0; i < gr[v].size(); i++)
      all[gr[v][i]]->now_color = 'B' + 'R' - all[gr[v][i]]->now_color;
    ans.push_back(v);
  }
  for (int i = 0; i < gr[v].size(); i++) {
    int to = (all[gr[v][i]]->a == v ? all[gr[v][i]]->b : all[gr[v][i]]->a);
    if (u[to] != cnt) {
      dfs_draw(to, c, (all[gr[v][i]]->now_color != c));
    }
  }
}
bool dfs_check(int v, char c) {
  u[v] = cnt;
  for (int i = 0; i < gr[v].size(); i++) {
    if (all[gr[v][i]]->now_color != c) return false;
    int to = (all[gr[v][i]]->a == v ? all[gr[v][i]]->b : all[gr[v][i]]->a);
    if (u[to] != cnt)
      if (dfs_check(to, c) == false) return false;
  }
  return true;
}
bool solve(int v, char color, bool need) {
  ans.clear();
  cnt++;
  dfs_prepare(v);
  cnt++;
  dfs_draw(v, color, need);
  cnt++;
  return dfs_check(v, color);
}
int main() {
  bool red_can = true, blue_can = true;
  int n, m, a, b;
  char c;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    gr[a].push_back((int)all.size());
    gr[b].push_back((int)all.size());
    all.push_back(new edge(a, b, c));
  }
  for (int i = 1; i <= n; i++) {
    if (u[i] != cnt) {
      dfs(i);
      all_comp.push_back(i);
    }
  }
  for (int i = 0; i < all_comp.size(); i++) {
    if (red_can == true) {
      bool was = false;
      if (solve(all_comp[i], 'R', true)) {
        was = true;
        best = ans;
      }
      if (solve(all_comp[i], 'R', false)) {
        if (was == false || best.size() > ans.size()) best = ans;
        was = true;
      }
      if (was) {
        for (int j = 0; j < best.size(); j++) {
          ans_red.push_back(best[j]);
        }
        best.clear();
      } else
        red_can = false;
    }
    if (blue_can == true) {
      bool was = false;
      if (solve(all_comp[i], 'B', true)) {
        was = true;
        best = ans;
      }
      if (solve(all_comp[i], 'B', false)) {
        if (was == false || best.size() > ans.size()) best = ans;
        was = true;
      }
      if (was) {
        for (int j = 0; j < best.size(); j++) {
          ans_blue.push_back(best[j]);
        }
        best.clear();
      } else
        blue_can = false;
    }
  }
  if (!red_can && !blue_can) {
    cout << -1 << endl;
    return 0;
  }
  if (!red_can) {
    cout << ans_blue.size() << endl;
    for (int i = 0; i < ans_blue.size(); i++) cout << ans_blue[i] << " ";
    cout << endl;
    return 0;
  }
  if (!blue_can) {
    cout << ans_red.size() << endl;
    for (int i = 0; i < ans_red.size(); i++) cout << ans_red[i] << " ";
    cout << endl;
    return 0;
  }
  if (ans_red.size() < ans_blue.size())
    best = ans_red;
  else
    best = ans_blue;
  cout << best.size() << endl;
  for (int i = 0; i < best.size(); i++) cout << best[i] << " ";
  cout << endl;
  return 0;
}
