#include <bits/stdc++.h>
using namespace std;
const int maxN = 100010;
int N, M;
int cur_kind[maxN];
vector<int> kind_list[3];
vector<pair<int, int> > G[maxN];
void input() {
  cin >> N >> M;
  int u, v;
  char c;
  for (int i = 1; i <= M; i++) {
    cin >> u >> v >> c;
    G[u].push_back({v, c});
    G[v].push_back({u, c});
  }
}
bool getColoring(int node, int kind, char ch) {
  if (cur_kind[node] != 0) return cur_kind[node] == kind;
  cur_kind[node] = kind;
  kind_list[kind].push_back(node);
  bool ret = true;
  int nxt_kind;
  for (auto edge : G[node]) {
    if (edge.second == ch)
      nxt_kind = kind;
    else {
      if (kind == 1)
        nxt_kind = 2;
      else
        nxt_kind = 1;
    }
    ret &= getColoring(edge.first, nxt_kind, ch);
  }
  return ret;
}
bool solve(char ch, vector<int> &store) {
  for (int i = 1; i <= N; i++) cur_kind[i] = 0;
  for (int i = 1; i <= N; i++) {
    if (cur_kind[i] != 0) continue;
    kind_list[1].clear();
    kind_list[2].clear();
    if (!getColoring(i, 1, ch)) return false;
    if (kind_list[1].size() < kind_list[2].size()) {
      for (auto node : kind_list[1]) store.push_back(node);
    } else {
      for (auto node : kind_list[2]) store.push_back(node);
    }
  }
  return true;
}
void solve() {
  vector<int> v, vb, vr;
  bool ans = solve('R', vr);
  if (ans) v = vr;
  if (solve('B', vb)) {
    if (ans) {
      if (vb.size() < vr.size()) v = vb;
    } else
      v = vb;
    ans = true;
  }
  if (!ans)
    cout << "-1";
  else {
    cout << (int)v.size() << "\n";
    for (auto node : v) cout << node << " ";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  input();
  solve();
  return 0;
}
