#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  os << "[";
  for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
    if (it != t.begin()) os << ",";
    os << *it;
  }
  os << "]";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &t) {
  os << "{";
  for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
    if (it != t.begin()) os << ",";
    os << *it;
  }
  os << "}";
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
  return os << "(" << t.first << "," << t.second << ")";
}
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first - t.first, s.second - t.second);
}
const int INF = 1 << 28;
const double EPS = 1e-8;
const int MOD = 1000000007;
struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  bool unite(int x, int y) {
    if ((x = root(x)) != (y = root(y))) {
      if (d[y] < d[x]) swap(x, y);
      d[x] += d[y];
      d[y] = x;
    }
    return x != y;
  }
  bool find(int x, int y) { return root(x) == root(y); }
  int root(int x) { return d[x] < 0 ? x : d[x] = root(d[x]); }
  int size(int x = -1) { return x < 0 ? d.size() : -d[root(x)]; }
};
bool dfs(vector<vector<int> > &g, vector<int> &color, int u, int c,
         vector<int> &trace) {
  color[u] = c;
  trace.push_back(u);
  for (int v : g[u]) {
    if (color[v] == c) return false;
    if (!color[v] && !dfs(g, color, v, -c, trace)) return false;
  }
  return true;
}
int n, m;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  scanf("%d%d", &n, &m);
  UnionFind ufr(n), ufb(n);
  vector<pair<int, int> > er, emplace_back;
  char pr = 'B';
  for (int i = 0; i < (int)(m); i++) {
    int u, v;
    char c;
    scanf("%d%d %c", &u, &v, &c);
    u--;
    v--;
    if (pr != c) {
      swap(er, emplace_back);
      swap(ufr, ufb);
    }
    pr = c;
    er.emplace_back(u, v);
    ufb.unite(u, v);
  }
  vector<int> ans(n + 1);
  for (int _ = 0; _ < (int)(2); _++) {
    vector<vector<int> > g(n);
    for (auto e : er) {
      int u, v;
      tie(u, v) = e;
      u = ufr.root(u);
      v = ufr.root(v);
      g[u].push_back(v);
      g[v].push_back(u);
    }
    int f = 1;
    vector<int> color(n);
    int sum = 0;
    vector<int> v;
    vector<vector<int> > inv(n);
    for (int i = 0; i < (int)(n); i++) inv[ufr.root(i)].push_back(i);
    for (int i = 0; i < (int)(n); i++)
      if (ufr.root(i) == i && !color[i]) {
        vector<int> t;
        if (!dfs(g, color, i, 1, t)) f = 0;
        if (!f) break;
        vector<vector<int> > tmp(2);
        for (int u : t)
          for (int v : inv[u]) tmp[color[u] == 1].push_back(v);
        if (tmp[0].size() > tmp[1].size()) swap(tmp[0], tmp[1]);
        v.insert(v.end(), (tmp[0]).begin(), (tmp[0]).end());
      }
    if (f)
      if (ans.size() > v.size()) swap(ans, v);
    swap(er, emplace_back);
    swap(ufr, ufb);
  }
  if (ans.size() == n + 1)
    cout << -1 << endl;
  else {
    cout << ans.size() << endl;
    for (int x : ans) cout << x + 1 << " ";
    cout << endl;
  }
  return 0;
}
