#include <bits/stdc++.h>
using namespace std;
vector<int> eval;
vector<vector<pair<int, int> > > graph;
int n, m;
vector<int> countre[2];
vector<int> subscriptiondp;
int numSteps(int vertex, int parity) {
  if (subscriptiondp[vertex] != -2) return subscriptiondp[vertex];
  int acc = 0;
  if (eval[vertex] == -1) {
    eval[vertex] = 0;
    countre[eval[vertex]].push_back(vertex);
  }
  for (int i = 0; i < graph[vertex].size(); i++) {
    int neigh = graph[vertex][i].first;
    int color = graph[vertex][i].second ^ parity;
    if (eval[neigh] != -1) {
      if (eval[neigh] ^ eval[vertex] != color) {
        subscriptiondp[vertex] = -1;
        return -1;
      }
    } else {
      eval[neigh] = eval[vertex] ^ color;
      countre[eval[neigh]].push_back(neigh);
      int moresteps = numSteps(neigh, parity);
      if (moresteps == -1)
        return -1;
      else
        acc += moresteps;
    }
  }
  subscriptiondp[vertex] = acc;
  return acc;
}
vector<int> allcol(int parity) {
  vector<int> finalPrint;
  for (int i = 1; i <= n; i++) {
    countre[0].clear();
    countre[1].clear();
    int test = numSteps(i, parity);
    if (test == -1) {
      return {-1};
    }
    int toPrint = (countre[0].size() < countre[1].size()) ? 0 : 1;
    for (int i = 0; i < countre[toPrint].size(); i++) {
      finalPrint.push_back(countre[toPrint][i]);
    }
  }
  return finalPrint;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  graph = vector<vector<pair<int, int> > >(n + 1);
  eval = vector<int>(n + 1, -1);
  subscriptiondp = vector<int>(n + 1, -2);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    char color;
    cin >> v1 >> v2 >> color;
    int col = (color == 'B') ? 1 : 0;
    graph[v1].push_back({v2, col});
    graph[v2].push_back({v1, col});
  }
  vector<int> finalPrint1 = allcol(0);
  eval = vector<int>(n + 1, -1);
  subscriptiondp = vector<int>(n + 1, -2);
  vector<int> finalPrint2 = allcol(1);
  vector<int> finalPrint =
      (finalPrint1.size() < finalPrint2.size()) ? finalPrint1 : finalPrint2;
  if (finalPrint1.size() == 1) {
    if (finalPrint1[0] == -1) {
      finalPrint = finalPrint2;
    }
  }
  if (finalPrint2.size() == 1) {
    if (finalPrint2[0] == -1) {
      finalPrint = finalPrint1;
    }
  }
  if (finalPrint.size() != 0 && finalPrint[0] == -1) {
    cout << -1 << endl;
    return 0;
  }
  cout << finalPrint.size() << endl;
  for (int i = 0; i < finalPrint.size(); i++) {
    cout << finalPrint[i] << " ";
  }
  cout << endl;
  return 0;
}
