#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int N = 1000001;
vector<pair<long long, char> > g[N];
long long color[N];
bool sett[N];
vector<long long> ans1, ans2, comp;
long long st1, st2, c1, c2;
void dfs(long long s, char c) {
  color[s] = 1;
  long long i;
  for (i = 0; i < g[s].size(); i++)
    if (color[g[s][i].first] == 0) {
      if (g[s][i].second == c)
        sett[g[s][i].first] = sett[s];
      else
        sett[g[s][i].first] = !sett[s];
      if (sett[g[s][i].first] == true)
        c1++;
      else
        c2++;
      comp.push_back(g[s][i].first);
      dfs(g[s][i].first, c);
    } else {
      if ((sett[g[s][i].first] == sett[s] && g[s][i].second != c) ||
          (sett[g[s][i].first] != sett[s] && g[s][i].second == c)) {
        if (c == 'R')
          st1 = 1;
        else
          st2 = 1;
      }
    }
}
int main() {
  long long n, i, m, j;
  long long a, b;
  char c;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> a >> b >> c;
    g[a - 1].push_back(make_pair((b - 1), c));
    g[b - 1].push_back(make_pair((a - 1), c));
  }
  st1 = 0;
  st2 = 0;
  for (i = 0; i < n; i++) {
    color[i] = 0;
    sett[i] = 0;
  }
  for (i = 0; i < n; i++) {
    c1 = 0;
    c2 = 0;
    comp.clear();
    if (color[i] == 0) {
      sett[i] = true;
      c1++;
      comp.push_back(i);
      dfs(i, 'R');
    } else
      continue;
    if (c1 > c2) {
      for (j = 0; j < comp.size(); j++)
        if (sett[comp[j]] == 0) ans1.push_back(comp[j] + 1);
    } else {
      for (j = 0; j < comp.size(); j++)
        if (sett[comp[j]] == 1) ans1.push_back(comp[j] + 1);
    }
  }
  for (i = 0; i < n; i++) {
    color[i] = 0;
    sett[i] = 0;
  }
  for (i = 0; i < n; i++) {
    c1 = 0;
    c2 = 0;
    comp.clear();
    if (color[i] == 0) {
      sett[i] = true;
      c1++;
      comp.push_back(i);
      dfs(i, 'B');
    } else
      continue;
    if (c1 > c2) {
      for (j = 0; j < comp.size(); j++)
        if (sett[comp[j]] == 0) ans2.push_back(comp[j] + 1);
    } else {
      for (j = 0; j < comp.size(); j++)
        if (sett[comp[j]] == 1) ans2.push_back(comp[j] + 1);
    }
  }
  if (st1 == 1 && st2 == 1)
    cout << -1 << endl;
  else if ((st1 == 0 && st2 == 0 && ans1.size() <= ans2.size()) ||
           (st1 == 0 && st2 == 1)) {
    cout << ans1.size() << endl;
    for (i = 0; i < ans1.size(); i++) cout << ans1[i] << ' ';
    cout << endl;
  } else if ((st2 == 0 && st1 == 0 && ans2.size() <= ans1.size()) ||
             (st1 == 1 && st2 == 0)) {
    cout << ans2.size() << endl;
    for (i = 0; i < ans2.size(); i++) cout << ans2[i] << ' ';
    cout << endl;
  }
}
