#include <bits/stdc++.h>
using namespace std;
int n, m;
struct Road {
  int f, t;
  bool type;
  inline int to(const int& from) {
    if (from == f)
      return t;
    else
      return f;
  }
} r[100009];
struct Vir {
  bool visited[2];
  bool flipped[2][2];
  list<Road*> r;
} v[100009];
bool tp[2];
int tcnt[2];
int tmpansw[2][100009];
bool p[2];
int cnt[2];
int answ[2][100009];
void DFS() {}
void DFS(int a, bool f1, bool f2, bool targ) {
  if (v[a].visited[targ]) {
    if (f1 != v[a].flipped[0][targ]) tp[0] = false;
    if (f2 != v[a].flipped[1][targ]) tp[1] = false;
  } else {
    v[a].visited[targ] = true;
    if (f1) {
      v[a].flipped[0][targ] = true;
      tmpansw[0][tcnt[0]++] = a;
    }
    if (f2) {
      v[a].flipped[1][targ] = true;
      tmpansw[1][tcnt[1]++] = a;
    }
    int t;
    bool type;
    for (list<Road*>::iterator it = v[a].r.begin(); it != v[a].r.end(); it++) {
      t = (*it)->to(a);
      type = (*it)->type;
      DFS(t, f1 xor type xor targ, f2 xor type xor targ, targ);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  char type;
  for (int i = 0; i < m; i++) {
    scanf("%d %d %c", &r[i].f, &r[i].t, &type);
    r[i].type = (type == 'B');
    v[r[i].f].r.push_back(&r[i]);
    v[r[i].t].r.push_back(&r[i]);
  }
  cnt[0] = cnt[1] = 0;
  p[0] = p[1] = true;
  for (int k = 1; k <= n; k++)
    v[k].visited[0] = v[k].visited[1] = v[k].flipped[0][0] =
        v[k].flipped[0][1] = v[k].flipped[1][0] = v[k].flipped[1][1] = false;
  for (int i = 1; i <= n; i++) {
    if (!v[i].visited[0]) {
      for (int t = 0; t < 2; t++) {
        tp[0] = tp[1] = true;
        tcnt[0] = tcnt[1] = 0;
        DFS(i, true, false, t);
        bool exist = tp[0] || tp[1];
        if (exist) {
          int sm = 0;
          if (tp[0] && tp[1])
            sm = (tcnt[0] < tcnt[1]) ? sm = 0 : sm = 1;
          else if (tp[0])
            sm = 0;
          else if (tp[1])
            sm = 1;
          for (int i = 0; i < tcnt[sm]; i++) {
            answ[t][cnt[t]++] = tmpansw[sm][i];
          }
        } else {
          p[t] = 0;
        }
      }
    }
  }
  int a = -1;
  if (p[0] && p[1])
    a = (cnt[0] < cnt[1]) ? 0 : 1;
  else if (p[0])
    a = 0;
  else if (p[1])
    a = 1;
  if (a == -1)
    printf("-1");
  else {
    printf("%d\n", cnt[a]);
    for (int i = 0; i < cnt[a]; i++) printf("%d ", answ[a][i]);
  }
  return 0;
}
