#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 10;
vector<int> adj[MAX_N][2];
vector<int> ans;
vector<int> g[2];
vector<vector<int>> b, r;
int B, R;
int mark[MAX_N];
bool dfs(int u, bool x) {
  bool ans = true;
  g[mark[u] - 1].push_back(u);
  for (auto i : adj[u][x]) {
    if (!mark[i])
      mark[i] = mark[u], ans &= dfs(i, x);
    else if (mark[i] != mark[u])
      ans = false;
  }
  for (auto i : adj[u][!x]) {
    if (!mark[i])
      mark[i] = 3 - mark[u], ans &= dfs(i, x);
    else if (mark[i] == mark[u])
      ans = false;
  }
  return ans;
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  while (m--) {
    char c;
    int u, v;
    cin >> u >> v >> c;
    u--, v--;
    bool x = (c == 'B');
    adj[u][x].push_back(v);
    adj[v][x].push_back(u);
  }
  for (int i = 0; i < n; i++) {
    if (!mark[i]) {
      g[0].clear(), g[1].clear();
      mark[i] = 1;
      if (dfs(i, 0)) {
        bool x = (((int)(g[1]).size()) < ((int)(g[0]).size()));
        b.push_back(g[x]), B += ((int)(g[x]).size());
      } else
        B = MAX_N;
      for (auto j : g[0]) mark[j] = 0;
      for (auto j : g[1]) mark[j] = 0;
      g[0].clear(), g[1].clear();
      mark[i] = 1;
      if (dfs(i, 1)) {
        bool x = (((int)(g[1]).size()) < ((int)(g[0]).size()));
        r.push_back(g[x]), R += ((int)(g[x]).size());
      } else
        R = MAX_N;
    }
  }
  if (min(R, B) >= MAX_N) return cout << "-1\n", 0;
  if (R < B) {
    cout << R << endl;
    for (auto v : r)
      for (auto i : v) cout << i + 1 << ' ';
  } else {
    cout << B << endl;
    for (auto v : b)
      for (auto i : v) cout << i + 1 << ' ';
  }
  return 0;
}
