#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
struct edge {
  int to, color;
  edge() {}
  edge(int to, int color) : to(to), color(color) {}
};
int n, m;
vector<edge> g[N];
int color[N];
int cnt_col[2];
vector<int> ans[2];
int an[2][N];
int ann[2];
bool ok[2];
void dfs(int x, int col, int flag) {
  if (ok[flag] == false) return;
  if (color[x] == -1) {
    color[x] = col;
    cnt_col[col]++;
    an[col][ann[col]++] = x;
    for (int i = 0; i < g[x].size(); i++) {
      int temp = (g[x][i].color == flag ? col : col ^ 1);
      dfs(g[x][i].to, temp, flag);
    }
  } else {
    if (color[x] != col) ok[flag] = false;
    return;
  }
}
int main() {
  cin >> n >> m;
  int u, v;
  char col;
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> col;
    int flag = (col == 'R' ? 0 : 1);
    g[u].push_back(edge(v, flag));
    g[v].push_back(edge(u, flag));
  }
  memset(color, -1, sizeof(color));
  ok[0] = true;
  for (int i = 1; i <= n; i++) {
    if (color[i] == -1) {
      cnt_col[0] = cnt_col[1] = 0;
      ann[0] = ann[1] = 0;
      dfs(i, 0, 0);
      if (ok[0] == false) break;
      int index = (cnt_col[0] < cnt_col[1] ? 0 : 1);
      for (int j = 0; j < ann[index]; j++) ans[0].push_back(an[index][j]);
    }
  }
  memset(color, -1, sizeof(color));
  ok[1] = true;
  for (int i = 1; i <= n; i++) {
    if (color[i] == -1) {
      cnt_col[0] = cnt_col[1] = 0;
      ann[0] = ann[1] = 0;
      dfs(i, 0, 1);
      if (ok[1] == false) break;
      int index = (cnt_col[0] < cnt_col[1] ? 0 : 1);
      for (int j = 0; j < ann[index]; j++) ans[1].push_back(an[index][j]);
    }
  }
  if (ok[0] == false && ok[1] == false)
    cout << -1 << endl;
  else {
    int index;
    if (ok[0] == false)
      index = 1;
    else if (ok[1] == false)
      index = 0;
    else
      index = (ans[0].size() < ans[1].size() ? 0 : 1);
    cout << ans[index].size() << endl;
    for (int i = 0; i < ans[index].size(); i++) {
      if (i) cout << ' ';
      cout << ans[index][i];
    }
    cout << endl;
  }
  return 0;
}
