#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
vector<int> vc[100001], vp[100001];
pair<int, pair<int, int> > pp[100001];
int vis[100001], fl;
vector<int> v1, v2;
void dfs(int c, int p) {
  vis[c] = p + 1;
  if (p == 0)
    v1.push_back(c);
  else
    v2.push_back(c);
  for (int i = (0); i < (vc[c].size()); ++i) {
    if (vis[vc[c][i]] == 0) dfs(vc[c][i], p ^ vp[c][i]);
    if ((vis[vc[c][i]] - 1) != (p ^ vp[c][i])) fl = 1;
  }
}
vector<int> res[2];
int go(int n, int m, int f) {
  for (int i = (1); i < (n + 1); ++i) vc[i].clear(), vp[i].clear();
  memset(vis, 0, sizeof vis);
  for (int i = (0); i < (m); ++i) {
    pp[i].first ^= f;
    if (pp[i].first == 0) {
      vc[pp[i].second.first].push_back(pp[i].second.second);
      vp[pp[i].second.first].push_back(1);
      vc[pp[i].second.second].push_back(pp[i].second.first);
      vp[pp[i].second.second].push_back(1);
    } else {
      vc[pp[i].second.first].push_back(pp[i].second.second);
      vp[pp[i].second.first].push_back(0);
      vc[pp[i].second.second].push_back(pp[i].second.first);
      vp[pp[i].second.second].push_back(0);
    }
  }
  fl = 0;
  int tot = 0;
  for (int i = (1); i < (n + 1); ++i) {
    if (vis[i] == 0) {
      v1.clear();
      v2.clear();
      dfs(i, 0);
      if (v1.size() > v2.size()) v1 = v2;
      tot += v1.size();
      for (int j = (0); j < (v1.size()); ++j) res[f].push_back(v1[j]);
    }
  }
  for (int i = (0); i < (m); ++i) {
    if (pp[i].first == 1) {
      if (vis[pp[i].second.first] != vis[pp[i].second.second]) fl = 1;
    }
  }
  if (fl == 0)
    return tot;
  else
    return 1000000007ll;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = (0); i < (m); ++i) {
    int x, y;
    string s;
    cin >> x >> y >> s;
    if (s == "B")
      pp[i] = make_pair(0, make_pair(x, y));
    else
      pp[i] = make_pair(1, make_pair(x, y));
  }
  int t1 = go(n, m, 0);
  int t2 = go(n, m, 1);
  if (t1 > n && t2 > n) {
    cout << -1 << endl;
    return 0;
  } else if (t1 > t2)
    res[0] = res[1];
  cout << res[0].size() << endl;
  for (int i = (0); i < (res[0].size()); ++i) cout << res[0][i] << " ";
  cout << endl;
}
