#include <bits/stdc++.h>
using namespace std;
long long n;
int explore[100005];
vector<pair<long long, long long>> v[100005];
vector<long long> heap[2];
bool dfs(long long x, bool s, char c) {
  if (explore[x] != -1) return explore[x] == s;
  explore[x] = s;
  heap[s].push_back(x);
  bool ret = 1;
  for (auto q : v[x]) ret &= dfs(q.first, q.second == c ? s : !s, c);
  return ret;
}
vector<long long> solve(char c) {
  memset(explore, -1, sizeof explore);
  vector<long long> ans;
  for (long long i = (long long)(1); i <= (long long)(n); i++)
    if (explore[i] == -1) {
      heap[0].clear();
      heap[1].clear();
      if (!dfs(i, 0, c)) return vector<long long>(n + 1, -1);
      int smallestHeap = 1;
      if (heap[0].size() <= heap[1].size()) smallestHeap = 0;
      for (long long x : heap[smallestHeap]) ans.push_back(x);
    }
  return ans;
}
int main() {
  long long m;
  cin >> n >> m;
  for (long long i = (long long)(1); i <= (long long)(m); i++) {
    long long x, y;
    char c;
    cin >> x >> y >> c;
    v[x].push_back({y, c});
    v[y].push_back({x, c});
  }
  auto R = solve('R');
  auto B = solve('B');
  if (R.size() > B.size()) R = B;
  if ((int)R.size() > n) {
    cout << -1;
    return 0;
  }
  cout << R.size() << '\n';
  for (long long x : R) cout << x << ' ';
}
