#include <bits/stdc++.h>
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
int n, m;
vector<ii> edges[100001];
vector<int> color[2][200001];
int visit[2][100001];
bool dfs(int now, int c, int goal) {
  for (auto& e : edges[now]) {
    int nextColor = c;
    if (goal != e.second) nextColor = c - (c - 1) % 2 + c % 2;
    if (visit[goal][e.first] == 0) {
      color[goal][nextColor].push_back(e.first);
      visit[goal][e.first] = nextColor;
      if (!dfs(e.first, nextColor, goal)) return false;
    } else if (visit[goal][e.first] != nextColor)
      return false;
  }
  return true;
}
int coloring(int goal) {
  int c = 1;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (visit[goal][i] != 0) continue;
    visit[goal][i] = c;
    color[goal][c].push_back(i);
    if (!dfs(i, c, goal)) return 987654321;
    ans += min(color[goal][c].size(), color[goal][c + 1].size());
    c += 2;
  }
  return ans;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    char buf[5];
    scanf("%d %d %s", &a, &b, buf);
    int t = 0;
    if (buf[0] == 'B') t = 1;
    edges[a].emplace_back(b, t);
    edges[b].emplace_back(a, t);
  }
  int a = coloring(0);
  int b = coloring(1);
  int res = min(a, b);
  if (res == 987654321) {
    printf("-1");
    return 0;
  }
  printf("%d\n", res);
  int k = 0;
  if (a > b) {
    k = 1;
  }
  int c = 1;
  while (!color[k][c].empty()) {
    int u = c;
    if (color[k][c + 1].size() < color[k][c].size()) u = c + 1;
    for (auto& v : color[k][u]) {
      printf("%d ", v);
    }
    c += 2;
  }
  return 0;
}
