#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<bool, int> > adj[100004];
bool v[100005];
bool si[100005];
set<int> s1, s2;
bool dfs(int here, bool bb, bool c) {
  v[here] = true;
  si[here] = bb;
  if (bb)
    s1.insert(here);
  else
    s2.insert(here);
  bool ret1 = true;
  for (int i = 0; i < adj[here].size(); i++) {
    int there = adj[here][i].second;
    int isB = adj[here][i].first;
    if (isB == c) {
      if (v[there]) {
        if (si[there] != si[here])
          continue;
        else
          return ret1 = false;
      } else {
        dfs(there, !bb, c);
      }
    } else {
      if (v[there]) {
        if (si[there] == si[here])
          continue;
        else
          return ret1 = false;
      } else {
        dfs(there, bb, c);
      }
    }
  }
  return ret1;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    char r;
    cin >> x >> y >> r;
    if (r == 'B') {
      adj[x].push_back(make_pair(true, y));
      adj[y].push_back(make_pair(true, x));
    } else {
      adj[x].push_back(make_pair(false, y));
      adj[y].push_back(make_pair(false, x));
    }
  }
  vector<int> ret1;
  for (int i = 1; i <= n; i++) {
    if (!v[i]) {
      s1.clear();
      s2.clear();
      if (!dfs(i, true, true)) {
        ret1 = vector<int>(1000001, 1);
        break;
      }
      if (s1.size() <= s2.size()) {
        for (set<int>::iterator it = s1.begin(); it != s1.end(); it++) {
          ret1.push_back(*it);
        }
      } else {
        for (set<int>::iterator it = s2.begin(); it != s2.end(); it++) {
          ret1.push_back(*it);
        }
      }
    }
  }
  vector<int> ret2;
  for (int i = 0; i < n + 1; i++) v[i] = false;
  for (int i = 1; i <= n; i++) {
    if (!v[i]) {
      s1.clear();
      s2.clear();
      if (!dfs(i, true, false)) {
        ret2 = vector<int>(1000001, 1);
        break;
      }
      if (s1.size() <= s2.size()) {
        for (set<int>::iterator it = s1.begin(); it != s1.end(); it++) {
          ret2.push_back(*it);
        }
      } else {
        for (set<int>::iterator it = s2.begin(); it != s2.end(); it++) {
          ret2.push_back(*it);
        }
      }
    }
  }
  vector<int> ret;
  if (ret1.size() < ret2.size())
    ret = ret1;
  else
    ret = ret2;
  if (ret.size() == 1000001) {
    cout << -1 << endl;
    return 0;
  }
  cout << ret.size() << endl;
  for (int i = 0; i < ret.size(); i++) {
    cout << ret[i] << ' ';
  }
  cout << endl;
  return 0;
}
