#include <bits/stdc++.h>
using namespace std;
int n, m;
int a, b;
int note;
int V[1 << 18];
bool vis[1 << 18], ok;
vector<int> T[3], A[3];
char c;
vector<pair<int, int> > E[1 << 18];
void dfs(int node, int pr, int val) {
  vis[node] = 1;
  for (auto i : E[node]) {
    if (vis[i.first] && i.first != pr) {
      if (i.second == val && V[i.first] != V[node]) ok = 1;
      if (i.second != val && V[i.first] == V[node]) ok = 1;
    }
    if (!vis[i.first]) {
      if (i.second == val)
        V[i.first] = V[node], T[V[node]].push_back(i.first);
      else
        V[i.first] = 1 - V[node], T[1 - V[node]].push_back(i.first);
      dfs(i.first, node, val);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d\n%c", &a, &b, &c);
    E[a].push_back({b, c == 'B'});
    E[b].push_back({a, c == 'B'});
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      T[0].push_back(i);
      dfs(i, 0, 0);
      if (T[0].size() <= T[1].size()) {
        for (auto h : T[0]) A[0].push_back(h);
      } else {
        for (auto h : T[1]) A[0].push_back(h);
      }
      T[0].clear();
      while (!T[1].empty()) V[T[1].back()] = 0, T[1].pop_back();
      if (ok) {
        note++;
        A[0].resize((1 << 18));
        break;
      }
    }
  }
  memset(vis, 0, sizeof(vis));
  ok = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      T[0].push_back(i);
      dfs(i, 0, 1);
      if (T[0].size() <= T[1].size()) {
        for (auto h : T[0]) A[1].push_back(h);
      } else {
        for (auto h : T[1]) A[1].push_back(h);
      }
      T[0].clear();
      while (!T[1].empty()) V[T[1].back()] = 0, T[1].pop_back();
      if (ok) {
        note++;
        A[1].resize((1 << 18));
        break;
      }
    }
  }
  if (note == 2) {
    printf("-1");
    return 0;
  }
  if (A[0].size() <= A[1].size()) {
    printf("%d\n", A[0].size());
    for (auto i : A[0]) printf("%d ", i);
    return 0;
  }
  printf("%d\n", A[1].size());
  for (auto i : A[1]) printf("%d ", i);
}
