#include <bits/stdc++.h>
using namespace std;
inline int GA(long long n, vector<long long>& vec) {
  for (long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    vec.push_back(x);
  }
}
vector<pair<long long, char> > vec[100001];
inline int GAEG(long long m, vector<long long> vec[]) {
  for (long long i = 0; i < m; ++i) {
    long long x, y;
    cin >> x >> y;
    x--, y--;
    vec[x].push_back(y);
  }
}
long long vis[100001];
long long n, m;
vector<long long> s[3];
bool D(long long x, long long r, char ch) {
  if (vis[x]) return vis[x] == r;
  vis[x] = r;
  s[r].push_back(x);
  for (auto i : vec[x])
    if (!D(i.first, (i.second == ch) ? r : r ^ 3, ch)) return false;
  return true;
}
vector<long long> second(char ch) {
  for (long long i = 0; i < 3; ++i) s[i].clear();
  memset(vis, 0, sizeof(vis));
  vector<long long> ans;
  ans.clear();
  for (long long i = 0; i < n; ++i) {
    if (!vis[i]) {
      for (long long j = 0; j < 3; ++j) s[j].clear();
      if (!D(i, 1, ch)) {
        for (long long i = 0; i < n + 1; ++i) ans.push_back(0);
        return ans;
      }
      long long qq = 1;
      if (s[1].size() > s[2].size()) qq = 2;
      ans.insert(ans.end(), s[qq].begin(), s[qq].end());
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> m;
  for (long long i = 0; i < m; ++i) {
    long long x, y;
    char ch;
    cin >> x >> y >> ch;
    vec[x].push_back(make_pair(y, ch));
    vec[y].push_back(make_pair(x, ch));
  }
  vector<long long> veco = second('R');
  vector<long long> vect = second('B');
  if (vect.size() == n + 1 && veco.size() == n + 1)
    return cout << -1 << endl, 0;
  vector<long long> ans = (vect.size() > veco.size()) ? veco : vect;
  cout << ans.size() << endl;
  for (auto i : ans) cout << i << " ";
  return 0;
}
