#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<pair<int, int> > adj[N];
int n, m, d[N];
vector<int> temp;
long long dfs(int cur, int e, int t) {
  if ((~d[cur]) && (d[cur] ^ e) != t) return n + 1;
  if (~d[cur]) return 0;
  d[cur] = (e ^ t);
  if (d[cur]) temp.push_back(cur);
  long long ret = d[cur];
  for (int i = 0; i < adj[cur].size(); ++i) {
    int to = adj[cur][i].first;
    int c = adj[cur][i].second;
    c ^= d[cur];
    ret += dfs(to, c, t);
  }
  return ret;
}
void solve(vector<int> &vec, long long &out, int t) {
  memset(d, -1, sizeof d);
  vector<int> v1, v2;
  temp.clear();
  for (int i = 0; i < n; ++i) {
    if (d[i] == -1) v1.push_back(dfs(i, 0, t));
  }
  memset(d, -1, sizeof d);
  temp.clear();
  for (int i = 0; i < n; ++i) {
    if (d[i] == -1) v2.push_back(dfs(i, 1, t));
  }
  memset(d, -1, sizeof d);
  temp.clear();
  int j = 0;
  out = 0;
  for (int i = 0; i < n; ++i) {
    if (d[i] == -1) {
      if (v1[j] < v2[j])
        dfs(i, 0, t);
      else
        dfs(i, 1, t);
      out += min(v1[j], v2[j]);
      j++;
    }
  }
  vec = temp;
}
int main() {
  scanf("%d", &n), scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    int u, v;
    char c;
    scanf("%d", &u), scanf("%d", &v);
    u--, v--;
    scanf(" %c", &c);
    adj[u].push_back(pair<int, int>(v, (c == 'B' ? 0 : 1)));
    adj[v].push_back(pair<int, int>(u, (c == 'B' ? 0 : 1)));
  }
  long long out1, out2;
  vector<int> v1, v2;
  solve(v1, out1, 0);
  solve(v2, out2, 1);
  if (out1 > n && out2 > n) return puts("-1");
  if (out2 < out1) swap(out1, out2), swap(v1, v2);
  cout << out1 << endl;
  for (int i = 0; i < v1.size(); ++i) printf("%d ", v1[i] + 1);
}
