#include <bits/stdc++.h>
using namespace std;
struct edge {
  int b;
  char color;
};
vector<edge> to[111111];
int n, m;
int vis[111111];
vector<int> pset[3];
bool dfs(int now, int st, char target) {
  if (vis[now]) return vis[now] == st;
  vis[now] = st;
  pset[st].push_back(now);
  for (auto x : to[now])
    if (!dfs(x.b, x.color == target ? st : (st ^ 3), target)) return false;
  return true;
}
pair<bool, vector<int>> test(char target) {
  vector<int> rtn;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      pset[1].clear();
      pset[2].clear();
      if (!dfs(i, 1, target)) return {false, rtn};
      int sel;
      if (pset[1].size() < pset[2].size())
        sel = 1;
      else
        sel = 2;
      for (auto x : pset[sel]) rtn.push_back(x);
    }
  return {true, rtn};
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i != m; i++) {
    int u, v;
    char c[3];
    scanf("%d%d%s", &u, &v, c);
    to[u].push_back({v, c[0]});
    to[v].push_back({u, c[0]});
  }
  pair<bool, vector<int>> res[2];
  res[0] = test('R');
  res[1] = test('B');
  if (!res[0].first && !res[1].first) return 0 * puts("-1");
  int sel;
  if (res[0].first &&
      (!res[1].first || res[0].second.size() < res[1].second.size()))
    sel = 0;
  else
    sel = 1;
  printf("%d\n", res[sel].second.size());
  for (auto x : res[sel].second) printf("%d ", x);
  return 0;
}
