#include <bits/stdc++.h>
using namespace std;
bool all_good;
vector<int> w[2];
vector<int> v1[200000];
vector<int> v2[200000];
int color[200000];
vector<int> res;
int n, m;
int x[200000];
int y[200000];
char q[200000];
void dfs(int x, int c) {
  w[c].push_back(x);
  if (!all_good) return;
  color[x] = c;
  for (int i = 0; i < v1[x].size(); i++) {
    int to = v1[x][i];
    if (color[to] == -1) {
      dfs(to, 1 - c);
    } else {
      if (color[to] == color[x]) {
        all_good = false;
        return;
      }
    }
  }
  for (int i = 0; i < v2[x].size(); i++) {
    int to = v2[x][i];
    if (color[to] == -1) {
      dfs(to, c);
    } else {
      if (color[to] != color[x]) {
        all_good = false;
        return;
      }
    }
  }
}
vector<int> solve(char qq) {
  res.clear();
  all_good = true;
  for (int i = 1; i <= n; i++) {
    v1[i].clear();
    v2[i].clear();
    color[i] = -1;
  }
  for (int i = 1; i <= m; i++)
    if (q[i] == qq) {
      v1[x[i]].push_back(y[i]);
      v1[y[i]].push_back(x[i]);
    } else {
      v2[x[i]].push_back(y[i]);
      v2[y[i]].push_back(x[i]);
    }
  for (int i = 1; i <= n; i++)
    if (color[i] == -1) {
      w[0].clear();
      w[1].clear();
      dfs(i, 0);
      if (w[0].size() > w[1].size()) swap(w[0], w[1]);
      for (int j = 0; j < w[0].size(); j++) res.push_back(w[0][j]);
    }
  if (!all_good) {
    res.clear();
    res.push_back(-1);
  }
  return res;
}
void prnt(vector<int> a) {
  cout << a.size() << "\n";
  for (int i = 0; i < a.size(); i++) cout << a[i] << ' ';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  bool fr = true;
  bool fb = true;
  for (int i = 1; i <= m; i++) {
    cin >> x[i] >> y[i] >> q[i];
    if (q[i] == 'B')
      fb = false;
    else
      fr = false;
  }
  if (fb || fr) {
    cout << "0\n";
    return 0;
  }
  vector<int> ans1 = solve('B');
  vector<int> ans2 = solve('R');
  if (ans1[0] == -1 && ans2[0] == -1) {
    cout << "-1\n";
    return 0;
  }
  if (ans2[0] == -1 || (ans1[0] != -1 && ans1.size() < ans2.size()))
    prnt(ans1);
  else
    prnt(ans2);
}
