#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, char> > link[100005];
int visited[100005];
vector<int> part[3];
bool dfs(int u, int p, char c) {
  if (visited[u] != 0) {
    return visited[u] == p;
  }
  visited[u] = p;
  part[p].push_back(u);
  for (int i = 0; i < link[u].size(); i++) {
    pair<int, char> x = link[u][i];
    if (dfs(x.first, x.second == c ? p : p ^ 3, c) == false) return false;
  }
  return true;
}
vector<int> solve(char c) {
  memset(visited, 0, sizeof(visited));
  vector<int> ans;
  for (int i = 1; i <= n; i++) {
    if (visited[i] == 0) {
      part[1].clear();
      part[2].clear();
      if (dfs(i, 1, c) == false) {
        for (int i = 0; i <= n; i++) ans.push_back(-1);
        return ans;
      }
      int f = 1;
      if (part[2].size() < part[1].size()) f = 2;
      ans.insert(ans.end(), part[f].begin(), part[f].end());
    }
  }
  return ans;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    link[a].push_back(make_pair(b, c));
    link[b].push_back(make_pair(a, c));
  }
  vector<int> f = solve('R');
  vector<int> g = solve('B');
  if (g.size() < f.size()) f = g;
  if (f.size() > n) {
    cout << "-1" << endl;
    return 0;
  }
  cout << f.size() << endl;
  for (int i = 0; i < f.size(); i++) cout << f[i] << " ";
  cout << endl;
  return 0;
}
