#include <bits/stdc++.h>
struct EDGE {
  int u, v, c;
} e[1000010];
struct edge {
  int b, ne;
} da[2 * 1000010];
int head[1000010], TOT, fa[1000010];
void insert(int a, int b) {
  da[++TOT].b = b;
  da[TOT].ne = head[a];
  head[a] = TOT;
}
int anc(int x) { return fa[x] == x ? x : fa[x] = anc(fa[x]); }
int col[1000010], q[1000010];
std::vector<int> v[1000010], S[2], Ans[2];
void bfs(int Y) {
  int op = 0, cl = 1;
  q[1] = Y;
  while (op < cl) {
    int x = q[++op];
    for (int i = 0; i < v[x].size(); i++) Ans[col[x]].push_back(v[x][i]);
    for (int t = head[x]; t; t = da[t].ne)
      if (col[da[t].b] == -1) col[da[t].b] = 1 - col[x], q[++cl] = da[t].b;
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &e[i].u, &e[i].v);
    char s[2];
    scanf("%s", s);
    e[i].c = s[0] == 'R' ? 0 : 1;
  }
  for (int COLOR = 0; COLOR < 2; COLOR++) {
    for (int i = 1; i <= n * 2; i++) fa[i] = i, v[i].clear(), fa[i + n] = i + n;
    for (int i = 1; i <= m; i++)
      if (COLOR == e[i].c)
        fa[anc(e[i].u)] = anc(e[i].v), fa[anc(e[i].u + n)] = anc(e[i].v + n);
      else {
        fa[anc(e[i].u)] = anc(e[i].v + n);
        fa[anc(e[i].u + n)] = anc(e[i].v);
      }
    bool g = true;
    for (int i = 1; i <= n; i++)
      if (anc(i) == anc(i + n)) {
        g = false;
        break;
      }
    if (!g) {
      S[COLOR].resize(n + 1);
      continue;
    }
    for (int i = 1; i <= n; i++) fa[i] = i;
    for (int i = 1; i <= m; i++)
      if (COLOR == e[i].c) fa[anc(e[i].u)] = anc(e[i].v);
    for (int i = 1; i <= n; i++) v[anc(i)].push_back(i);
    TOT = 0;
    memset(head, 0, sizeof head);
    for (int i = 1; i <= m; i++)
      if (COLOR != e[i].c)
        insert(anc(e[i].u), anc(e[i].v)), insert(anc(e[i].v), anc(e[i].u));
    memset(col, -1, sizeof col);
    for (int i = 1; i <= n; i++)
      if (fa[i] == i && col[i] == -1) {
        Ans[0].clear(), Ans[1].clear(), col[i] = 0, bfs(i);
        if (Ans[0].size() < Ans[1].size())
          for (int j = 0; j < Ans[0].size(); j++) S[COLOR].push_back(Ans[0][j]);
        else
          for (int j = 0; j < Ans[1].size(); j++) S[COLOR].push_back(Ans[1][j]);
      }
  }
  if (S[0].size() == n + 1 && S[1].size() == n + 1)
    printf("-1");
  else if (S[0].size() < S[1].size()) {
    printf("%d\n", S[0].size());
    for (int i = 0; i < S[0].size(); i++) printf("%d ", S[0][i]);
  } else {
    printf("%d\n", S[1].size());
    for (int i = 0; i < S[1].size(); i++) printf("%d ", S[1][i]);
  }
  return 0;
}
