#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9;
const int MAXN = 100000;
int n, m;
list<pair<int, char> > g[MAXN + 1];
int part[MAXN + 1];
list<int> parts[2];
bool dfs(int u, int p, char c) {
  if (part[u] != -1) return part[u] == p;
  part[u] = p;
  parts[p].push_back(u);
  bool can = true;
  for (auto e : g[u]) {
    if (e.second == c)
      can &= dfs(e.first, p, c);
    else
      can &= dfs(e.first, 1 - p, c);
  }
  return can;
}
vector<int> repaint(char c) {
  for (int i = 1; i <= n; ++i) part[i] = -1;
  vector<int> ans;
  for (int i = 1; i <= n; ++i)
    if (part[i] == -1) {
      parts[0].clear();
      parts[1].clear();
      bool can = dfs(i, 0, c);
      if (!can) return vector<int>(n + 1);
      if (parts[0].size() < parts[1].size())
        for (auto x : parts[0]) ans.push_back(x);
      else
        for (auto x : parts[1]) ans.push_back(x);
    }
  return ans;
}
void solve() {
  while (scanf("%d%d", &n, &m) == 2) {
    for (int i = 1; i <= n; ++i) g[i].clear();
    for (int i = 0; i < m; ++i) {
      int u, v;
      char c;
      scanf("%d %d %c", &u, &v, &c);
      g[u].push_back(make_pair(v, c));
      g[v].push_back(make_pair(u, c));
    }
    vector<int> blueAns = repaint('B');
    vector<int> redAns = repaint('R');
    vector<int> ans;
    if (blueAns.size() < redAns.size())
      ans = blueAns;
    else
      ans = redAns;
    if (ans.size() > n)
      printf("-1\n");
    else {
      printf("%d\n", ans.size());
      for (auto u : ans) printf("%d ", u);
      printf("\n");
    }
  }
}
int main() {
  solve();
  return 0;
}
