#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m;
int vis[maxn];
vector<int> part[3];
vector<pair<int, char> > g[maxn];
bool dfs(int u, int id, char c) {
  if (vis[u]) return vis[u] == id;
  vis[u] = id;
  part[id].push_back(u);
  for (auto x : g[u]) {
    if (!dfs(x.first, x.second == c ? id : id ^ 3, c)) return false;
  }
  return true;
}
vector<int> solve(char c) {
  memset(vis, 0, sizeof(vis));
  vector<int> ans;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    part[1].clear();
    part[2].clear();
    if (!dfs(i, 1, c)) {
      for (int j = 0; j <= n; j++) ans.push_back(0);
      return ans;
    }
    int t = 1;
    if (part[2].size() < part[1].size()) t = 2;
    ans.insert(ans.end(), part[t].begin(), part[t].end());
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    char s[3];
    scanf("%d%d%s", &u, &v, s);
    g[u].push_back(make_pair(v, s[0]));
    g[v].push_back(make_pair(u, s[0]));
  }
  auto r = solve('R');
  auto b = solve('B');
  if (r.size() < b.size()) b = r;
  if (b.size() > n)
    puts("-1");
  else {
    cout << b.size() << endl;
    for (int i = 0; i < b.size(); i++)
      printf("%d%c", b[i], i + 1 == b.size() ? '\n' : ' ');
  }
  return 0;
}
