#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, char>>> graph(100000);
bool visited[100000];
bool sets[100000];
vector<vector<int>> v(4);
bool dfs(int i) {
  visited[i] = true;
  for (int j = 0; j < graph[i].size(); j++) {
    if (visited[graph[i][j].first]) {
      if (graph[i][j].second == 'R' && sets[graph[i][j].first] != sets[i] ||
          graph[i][j].second == 'B' && sets[graph[i][j].first] == sets[i])
        return false;
    } else {
      if (graph[i][j].second == 'R') {
        sets[graph[i][j].first] = sets[i];
        if (!dfs(graph[i][j].first)) return false;
      } else {
        sets[graph[i][j].first] = !sets[i];
        if (!dfs(graph[i][j].first)) return false;
      }
      if (sets[graph[i][j].first])
        v[1].push_back(graph[i][j].first);
      else
        v[0].push_back(graph[i][j].first);
    }
  }
  return true;
}
bool dfs2(int i) {
  visited[i] = true;
  for (int j = 0; j < graph[i].size(); j++) {
    if (visited[graph[i][j].first]) {
      if (graph[i][j].second == 'B' && sets[graph[i][j].first] != sets[i] ||
          graph[i][j].second == 'R' && sets[graph[i][j].first] == sets[i])
        return false;
    } else {
      if (graph[i][j].second == 'B') {
        sets[graph[i][j].first] = sets[i];
        if (!dfs2(graph[i][j].first)) return false;
      } else {
        sets[graph[i][j].first] = !sets[i];
        if (!dfs2(graph[i][j].first)) return false;
      }
      if (sets[graph[i][j].first])
        v[3].push_back(graph[i][j].first);
      else
        v[2].push_back(graph[i][j].first);
    }
  }
  return true;
}
int main() {
  memset(visited, 0, sizeof visited);
  int n, m;
  cin >> n >> m;
  char c;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    graph[a - 1].push_back(make_pair(b - 1, c));
    graph[b - 1].push_back(make_pair(a - 1, c));
  }
  vector<int> v1;
  vector<int> v2;
  bool ans1 = true;
  for (int i = 0; i < n && ans1; i++)
    if (!visited[i]) {
      sets[i] = false;
      v[0].resize(0);
      v[1].resize(0);
      v[0].push_back(i);
      if (!dfs(i))
        ans1 = false;
      else {
        int k = v[0].size() < v[1].size() ? 0 : 1;
        for (int j = 0; j < v[k].size(); j++) v1.push_back(v[k][j]);
      }
    }
  bool ans2 = true;
  memset(visited, 0, sizeof visited);
  for (int i = 0; i < n && ans2; i++)
    if (!visited[i]) {
      sets[i] = false;
      v[2].resize(0);
      v[3].resize(0);
      v[2].push_back(i);
      if (!dfs2(i))
        ans2 = false;
      else {
        int k = v[3].size() < v[2].size() ? 3 : 2;
        for (int j = 0; j < v[k].size(); j++) v2.push_back(v[k][j]);
      }
    }
  vector<int> ans;
  if (ans1 || ans2) {
    if (!ans2) {
      ans = v1;
    } else if (!ans1) {
      ans = v2;
    } else {
      ans = (v1.size() < v2.size()) ? v1 : v2;
    }
    cout << ans.size() << endl;
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++) cout << ans[i] + 1 << " ";
    cout << endl;
  } else
    cout << "-1" << endl;
  return 0;
}
