#include <bits/stdc++.h>
using namespace std;
int clrs[100010];
vector<pair<int, int> > g[100010];
int swt[100010];
int cl;
vector<int> clg;
bool dfs(int u) {
  clg.push_back(u);
  for (auto e : g[u]) {
    int v = e.first;
    int i = e.second;
    if (swt[v] == -1) {
      swt[v] = swt[u] ^ clrs[i] ^ cl;
      dfs(v);
    } else if (swt[v] != (swt[u] ^ clrs[i] ^ cl))
      return false;
  }
  return true;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    char c;
    scanf("%d %d %c", &u, &v, &c);
    g[v].push_back({u, i});
    g[u].push_back({v, i});
    clrs[i] = (c == 'B');
  }
  pair<int, vector<int> > vs[2];
  for (cl = 0; cl <= 1; cl++) {
    vs[cl].first = 0;
    for (int i = 0; i <= n; i++) swt[i] = -1;
    for (int i = 1; i <= n; i++) {
      if (swt[i] != -1) continue;
      clg.clear();
      swt[i] = 0;
      if (!dfs(i)) {
        vs[cl].first = 10000000;
        break;
      }
      int num = 0;
      for (auto v : clg)
        if (swt[v] == 1) num++;
      if (num > clg.size() / 2)
        for (auto v : clg) {
          if (swt[v] == 1)
            swt[v] = 0;
          else if (swt[v] == 0)
            swt[v] = 1;
        }
    }
    if (vs[cl].first == 10000000) continue;
    for (int i = 1; i <= n; i++)
      if (swt[i] == 1) vs[cl].second.push_back(i);
    vs[cl].first = vs[cl].second.size();
  }
  pair<int, vector<int> > s = min(vs[0], vs[1]);
  if (s.first == 10000000) {
    printf("-1\n");
    return 0;
  }
  printf("%d\n", s.first);
  for (int v : s.second) printf("%d ", v);
  if (s.first != 0) printf("\n");
  return 0;
}
