#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
const int inf = 1e9;
int col[M], f[M], t[M], R;
int mark[M];
vector<int> adj[M];
vector<int> vecb, vecr;
int rang[M];
vector<int> ran[3];
bool fal = 0;
void dfs(int v) {
  mark[v] = 1, ran[rang[v]].push_back(v);
  for (int e : adj[v]) {
    int u = v ^ f[e] ^ t[e];
    if (rang[u]) {
      if (col[e] == R) {
        if (rang[u] != rang[v]) fal = 1;
      } else if (rang[u] == rang[v])
        fal = 1;
    }
    if (col[e] == R)
      rang[u] = rang[v];
    else
      rang[u] = 3 - rang[v];
    if (!mark[u]) dfs(u);
  }
}
int go(int v) {
  ran[1].clear();
  ran[2].clear();
  fal = 0;
  rang[v] = 1, dfs(v);
  if (fal) return -1;
  return min(ran[1].size(), ran[2].size());
}
int32_t main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> f[i] >> t[i];
    char c;
    cin >> c;
    col[i] = (int)(c == 'R');
    adj[f[i]].push_back(i);
    adj[t[i]].push_back(i);
  }
  int ans = 1e9;
  vector<int> vec;
  for (R = 0; R < 2; R++) {
    memset(mark, 0, sizeof mark);
    memset(rang, 0, sizeof rang);
    int kol = 0;
    vector<int> var;
    for (int i = 1; i <= n; i++)
      if (!mark[i]) {
        int x = go(i);
        if (~x)
          kol += x;
        else
          kol = inf;
        int s = 1;
        if (ran[2].size() < ran[1].size()) s = 2;
        for (int p : ran[s]) var.push_back(p);
      }
    if (kol < ans) {
      vec.clear();
      for (int p : var) vec.push_back(p);
      ((ans) = min((ans), (kol)));
    }
  }
  if (ans < inf) {
    cout << vec.size() << endl;
    for (int p : vec) cout << p << ' ';
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
