#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 20;
int visited[2][N], cl[2][N], n, m, flag = 1, t[2], fl[2], mainflag[2],
                                   listi[2][N], sor;
vector<pair<int, int> > adj[N];
char maincolor;
vector<int> ans[2], ted[2];
void dfs(int v, int mark) {
  visited[sor][v] = 1;
  cl[sor][v] = mark;
  ted[sor].push_back(v);
  if (mark == 1) {
    t[sor]++;
  }
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i].first;
    if (visited[sor][u] == 0) {
      if (adj[v][i].second == maincolor) {
        if (cl[sor][v] == 1)
          dfs(u, 1);
        else
          dfs(u, 0);
      } else {
        if (cl[sor][v] == 1)
          dfs(u, 0);
        else
          dfs(u, 1);
      }
    } else {
      if (adj[v][i].second == maincolor) {
        if (cl[sor][v] != cl[sor][u]) fl[sor] = 0;
      } else {
        if (cl[sor][v] == cl[sor][u]) fl[sor] = 0;
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    adj[x].push_back(make_pair(y, c));
    adj[y].push_back(make_pair(x, c));
  }
  mainflag[0] = 1;
  mainflag[1] = 1;
  for (int j = 0; j < 2; j++) {
    fill(visited[0], visited[0] + n + 1, 0);
    fill(visited[1], visited[1] + n + 1, 0);
    fill(cl[0], cl[0] + n + 1, 0);
    fill(cl[1], cl[1] + n + 1, 0);
    if (j == 0)
      maincolor = 'R';
    else
      maincolor = 'B';
    for (int i = 1; i <= n; i++) {
      if (visited[0][i] == 0) {
        ted[0].clear();
        ted[1].clear();
        fill(t, t + 2, 0);
        fill(fl, fl + 2, 1);
        for (int k = 0; k < 2; k++) {
          flag = 1;
          sor = k;
          dfs(i, k);
        }
        if (fl[0] == 0 and fl[1] == 0) {
          mainflag[j] = 0;
          break;
        }
        if (fl[0] == 1 and fl[1] == 1) {
          if (t[1] < t[0]) {
            for (int k2 = 0; k2 < ted[1].size(); k2++) {
              if (cl[1][ted[1][k2]] == 1) ans[j].push_back(ted[1][k2]);
            }
          } else {
            for (int k2 = 0; k2 < ted[0].size(); k2++) {
              if (cl[0][ted[0][k2]] == 1) ans[j].push_back(ted[0][k2]);
            }
          }
        } else if (fl[0] == 1) {
          for (int k2 = 0; k2 < ted[0].size(); k2++) {
            if (cl[0][ted[0][k2]] == 1) ans[j].push_back(ted[0][k2]);
          }
        } else {
          for (int k2 = 0; k2 < ted[1].size(); k2++) {
            if (cl[1][ted[1][k2]] == 1) ans[j].push_back(ted[1][k2]);
          }
        }
      }
    }
  }
  if (mainflag[0] == 0 and mainflag[1] == 0) {
    cout << -1;
    return 0;
  }
  if (mainflag[0] == 1 and mainflag[1] == 1) {
    if (ans[0].size() < ans[1].size()) {
      cout << ans[0].size() << "\n";
      for (int i = 0; i < ans[0].size(); i++) cout << ans[0][i] << " ";
    } else {
      cout << ans[1].size() << "\n";
      for (int i = 0; i < ans[1].size(); i++) cout << ans[1][i] << " ";
    }
  } else if (mainflag[0] == 1) {
    cout << ans[0].size() << "\n";
    for (int i = 0; i < ans[0].size(); i++) cout << ans[0][i] << " ";
  } else {
    cout << ans[1].size() << "\n";
    for (int i = 0; i < ans[1].size(); i++) cout << ans[1][i] << " ";
  }
}
