#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
bool no[2];
int group[N], cur_color;
vector<int> ver;
vector<pair<int, int> > g[N];
bitset<N> vis[2];
void dfs(int v, int which, int p = 0) {
  ver.push_back(v);
  group[v] = which;
  vis[cur_color][v] = 1;
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i].first;
    int c = g[v][i].second;
    if (to == p) continue;
    if (vis[cur_color][to]) {
      if (c == cur_color && group[to] != group[v] ||
          c != cur_color && group[to] == group[v]) {
        no[cur_color] = 1;
        return;
      }
      continue;
    }
    if (c == cur_color) {
      dfs(to, group[v], v);
    } else {
      dfs(to, group[v] ^ 1, v);
    }
    if (no[cur_color]) return;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  map<char, int> mp;
  mp['B'] = 1;
  mp['R'] = 0;
  for (int i = 1; i <= m; ++i) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    g[a].push_back({b, mp[c]});
    g[b].push_back({a, mp[c]});
  }
  vector<int> ans[2];
  for (cur_color = 0; cur_color < 2; ++cur_color) {
    for (int i = 1; i <= n; ++i) {
      if (!vis[cur_color][i]) {
        dfs(i, 0);
        if (no[cur_color]) {
          break;
        }
        int zero = 0, one = 0;
        for (int j = 0; j < ver.size(); ++j) {
          if (group[ver[j]])
            one++;
          else
            zero++;
        }
        int which = (one < zero);
        for (int j = 0; j < ver.size(); ++j) {
          if (group[ver[j]] == which) ans[cur_color].push_back(ver[j]);
        }
        ver.clear();
      }
    }
    for (int i = 0; i <= n; ++i) group[i] = 0;
    ver.clear();
  }
  if (no[0] && no[1])
    cout << -1 << '\n';
  else {
    int which;
    if (no[0])
      which = 1;
    else if (no[1])
      which = 0;
    else
      which = ((int)ans[1].size() < (int)ans[0].size());
    cout << ans[which].size() << '\n';
    for (int j = 0; j < ans[which].size(); ++j) cout << ans[which][j] << " ";
  }
  return 0;
}
