#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const long long Inf = 1e10;
const int P = 1e9 + 7;
const int N = 100005;
inline int IN() {
  int x = 0, ch = 0, f = 0;
  for (ch = getchar(); ch != -1 && (ch < 48 || ch > 57); ch = getchar())
    f = (ch == '-');
  for (; ch >= 48 && ch <= 57; ch = getchar())
    x = (x << 1) + (x << 3) + ch - '0';
  return f ? (-x) : x;
}
int Pow(int x, int y, int p) {
  int a = 1;
  for (; y; y >>= 1, x = (long long)x * x % p)
    if (y & 1) a = (long long)a * x % p;
  return a;
}
int n, m, res, fail, f[N];
vector<pair<int, int> > e[N];
int tot[2], go[N];
vector<int> ans;
vector<int> an;
int tt = inf, vis[N];
void DFS(int x, int ww) {
  vis[x] = 1;
  if (f[x] == -1) {
    f[x] = ww;
    go[++*go] = x;
    tot[ww]++;
  } else {
    if (f[x] != ww) {
      fail = 1;
      return;
    }
    return;
  }
  for (int i = (int)(0); i < (int)(e[x].size()); i++) {
    int v = e[x][i].first, w = e[x][i].second;
    w ^= res ^ ww;
    DFS(v, w);
    if (fail) return;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (int)(1); i <= (int)(m); i++) {
    int x, y;
    char c[2];
    scanf("%d%d%s", &x, &y, c);
    int t = (*c == 'B') ? 0 : 1;
    e[x].push_back(make_pair(y, t));
    e[y].push_back(make_pair(x, t));
  }
  for (res = 0; res <= 1; res++) {
    fail = 0;
    memset(f, -1, sizeof f);
    memset(vis, 0, sizeof vis);
    ans.clear();
    for (int i = (int)(1); i <= (int)(n); i++) {
      if (vis[i]) continue;
      tot[0] = tot[1] = 0;
      *go = 0;
      DFS(i, 0);
      if (fail) break;
      int pick = (tot[0] < tot[1]) ? 0 : 1;
      for (int j = (int)(1); j <= (int)(*go); j++)
        if (f[go[j]] == pick) ans.push_back(go[j]);
    }
    if (!fail) {
      int sz = (int)ans.size();
      if (sz < tt) {
        tt = sz;
        an = ans;
      }
    }
  }
  if (tt == inf) {
    puts("-1");
  } else {
    printf("%d\n", (int)an.size());
    for (int i = (int)(0); i < (int)(an.size()); i++) printf("%d ", an[i]);
  }
  return 0;
}
