#include <bits/stdc++.h>
using namespace std;
vector<pair<int, char> > grp[112345];
bool mark[112345];
vector<int> ans[2], p[3];
map<int, int> vp;
int n, e;
bool dfs(int part, char cl, int vx) {
  p[part].push_back(vx);
  mark[vx] = true;
  vp[vx] = part;
  for (int i = 0; i < grp[vx].size(); i++) {
    int v = grp[vx][i].first;
    char c = grp[vx][i].second;
    int x;
    if (c == cl)
      x = part;
    else
      x = part % 2 + 1;
    if (mark[v]) {
      if (vp[v] != x) return false;
    } else {
      if (!dfs(x, cl, v)) return false;
    }
  }
  return true;
}
bool solve(char clr, int as) {
  for (int i = 0; i <= n; i++) {
    mark[i] = false;
  }
  vp.clear();
  for (int i = 1; i <= n; i++) {
    p[0].clear();
    p[1].clear();
    p[2].clear();
    if (mark[i] == false) {
      if (dfs(1, clr, i) == true) {
        if (p[1].size() < p[2].size()) {
          for (int j = 0; j < p[1].size(); j++) ans[as].push_back(p[1][j]);
        } else {
          for (int j = 0; j < p[2].size(); j++) ans[as].push_back(p[2][j]);
        }
      } else {
        return false;
      }
    }
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &e);
  for (int i = 0; i < e; i++) {
    int x, y;
    char ch;
    cin >> x >> y >> ch;
    grp[x].push_back(make_pair(y, ch));
    grp[y].push_back(make_pair(x, ch));
  }
  bool sr = solve('R', 1), sb = solve('B', 0);
  int x = 1;
  if (!sr && !sb) {
    cout << -1 << endl;
    return 0;
  } else if (sr && sb) {
    if (ans[0].size() < ans[1].size()) x = 0;
  } else if (sr) {
    x = 1;
  } else
    x = 0;
  cout << ans[x].size() << endl;
  ;
  for (int i = 0; i < ans[x].size(); i++) cout << ans[x][i] << " ";
  cout << endl;
}
