#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 15;
vector<pair<int, char> > G[maxn];
int N, M, co[maxn], ok1, ok2;
char buffer[20];
vector<int> part[2];
bool dfs(int x, char target) {
  for (auto ev : G[x]) {
    int v = ev.first;
    char c = ev.second;
    if (c == target) {
      if (co[v] == -1) {
        co[v] = co[x];
        part[co[v]].push_back(v);
        if (!dfs(v, target)) return false;
      } else if (co[v] != co[x])
        return false;
    } else {
      if (co[v] == -1) {
        co[v] = co[x] ^ 1;
        part[co[v]].push_back(v);
        if (!dfs(v, target)) return false;
      } else if (co[v] == co[x])
        return false;
    }
  }
  return true;
}
vector<int> solve(char target) {
  memset(co, -1, sizeof(co));
  vector<int> res;
  for (int i = 1; i <= N; ++i)
    if (co[i] == -1) {
      for (int j = 0; j < 2; ++j) part[j].clear();
      co[i] = 0;
      part[0].push_back(i);
      if (!dfs(i, target)) {
        if (target == 'B')
          ok1 = false;
        else
          ok2 = false;
        return res;
      }
      vector<int>& s = part[0];
      if (s.size() > part[1].size()) s = part[1];
      for (auto it : s) res.push_back(it);
    }
  if (target == 'B')
    ok1 = true;
  else
    ok2 = true;
  return res;
}
int main(int argc, char* argv[]) {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= M; ++i) {
    int u, v;
    scanf("%d%d%s", &u, &v, buffer);
    G[u].push_back(make_pair(v, buffer[0]));
    G[v].push_back(make_pair(u, buffer[0]));
  }
  bool ok = false;
  vector<int> ans;
  vector<int> ta = solve('B');
  vector<int> tb = solve('R');
  if (ok1 == true) ans = ta, ok = true;
  if (ok2 == true) {
    if (ok == false)
      ans = tb, ok = true;
    else if (tb.size() < ta.size())
      ans = tb;
  }
  if (ok == false)
    printf("-1\n");
  else {
    printf("%d\n", (int)ans.size());
    for (auto it : ans) printf("%d ", it);
    printf("\n");
  }
  return 0;
}
