#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;
template <class T>
inline bool Min(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
inline bool Max(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
inline int ni() {
  int a;
  scanf("%d", &a);
  return a;
}
inline ll nl() {
  ll a;
  scanf("%lld", &a);
  return a;
}
inline double nd() {
  double a;
  scanf("%lf", &a);
  return a;
}
inline void pi(int a) { printf("%d ", a); }
inline void pl(ll a) { printf("%lld ", a); }
inline void pd(double a) { printf("%.12lf ", a); }
const int N = 1e5 + 10;
vector<pii> gp[N];
bool used[N];
int n, m;
vector<int> part[2];
char color[N];
bool dfs(int v, int Col, char ch) {
  if (used[v]) return color[v] == Col;
  color[v] = Col;
  used[v] = true;
  part[Col].emplace_back(v + 1);
  for (pii next : gp[v])
    if (!dfs(next.first, next.second == ch ? (Col) : (Col ^ 1), ch))
      return false;
  return true;
}
vector<int> solveFor(char ch) {
  fill(used, used + n, 0);
  fill(color, color + n, -1);
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      part[0].clear();
      part[1].clear();
      if (!dfs(i, 0, ch)) {
        for (int k = 0; k < (int)(n + n); ++k) ans.push_back(-1);
        return ans;
      }
      if (part[0].size() > part[1].size()) part[0].swap(part[1]);
      ans.insert(ans.end(), (part[0]).begin(), (part[0]).end());
    }
  }
  return ans;
}
void solve() {
  n = ni();
  m = ni();
  for (int i = 0; i < (int)(m); ++i) {
    int a, b;
    char c;
    scanf("%d %d %c", &a, &b, &c);
    a--, b--;
    gp[a].emplace_back(b, c);
    gp[b].emplace_back(a, c);
  }
  auto R = solveFor('R');
  auto B = solveFor('B');
  if (B.size() < R.size()) R = B;
  if (R.size() > n) {
    cout << -1;
    return;
  }
  cout << R.size() << endl;
  for (int v : R) cout << v << " ";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
