#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, char> edgecolor;
vector<int> graph[100005];
vector<int> part[3], newcolor;
bool solve(vector<int> &answer, char mainColor, int n) {
  int a, b;
  queue<int> q;
  newcolor.clear();
  newcolor.resize(n);
  for (int i = 0; i < n; i++) {
    if (newcolor[i] != 0) continue;
    q.push(i);
    newcolor[i] = 1;
    part[1].clear();
    part[2].clear();
    part[1].push_back(i + 1);
    while (!q.empty()) {
      a = q.front();
      q.pop();
      int color = newcolor[a];
      for (auto it = graph[a].begin(); it != graph[a].end(); it++) {
        b = *it;
        if (edgecolor[{a, b}] == mainColor) {
          if (newcolor[b] == 0) {
            newcolor[b] = color;
            part[color].push_back(b + 1);
            q.push(b);
          } else if (newcolor[b] == 3 - color) {
            return false;
          }
        } else {
          if (newcolor[b] == 0) {
            newcolor[b] = 3 - color;
            part[3 - color].push_back(b + 1);
            q.push(b);
          } else if (newcolor[b] == color) {
            return false;
          }
        }
      }
    }
    int f = 1;
    if (part[1].size() > part[2].size()) f = 2;
    answer.insert(answer.end(), part[f].begin(), part[f].end());
  }
  return true;
}
int main(int argc, char *argv[]) {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  int n, e;
  cin >> n >> e;
  char c;
  int a, b;
  for (int i = 0; i < e; i++) {
    cin >> a >> b >> c;
    assert(c == 'R' || c == 'B');
    a--, b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
    edgecolor[{a, b}] = c;
    edgecolor[{b, a}] = c;
  }
  vector<int> colorR, colorB;
  bool b1 = solve(colorR, 'R', n);
  bool b2 = solve(colorB, 'B', n);
  if (!b1 && b2)
    colorR = colorB;
  else if (b1 && b2) {
    if (colorR.size() > colorB.size()) colorR = colorB;
  } else if (!b1 && !b2) {
    cout << -1;
    exit(0);
  }
  cout << colorR.size() << endl;
  for (auto it = colorR.begin(); it != colorR.end(); it++) cout << *it << ' ';
  return 0;
}
