#include <bits/stdc++.h>
using namespace std;
void fre() {
  freopen("c://test//input.in", "r", stdin);
  freopen("c://test//output.out", "w", stdout);
}
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
  if (b < a) a = b;
}
const int N = 1e5 + 10, M = 1e5 + 10, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n, m;
struct Edge {
  int x, y;
  char ch;
  Edge(int x = 0, int y = 0, char ch = 0) : x(x), y(y), ch(ch){};
} e[M];
vector<pair<int, int> > a[N];
int c[N];
vector<int> way[4], tmp, ans;
bool dfs(int x, int col) {
  c[x] = col;
  way[col].push_back(x);
  for (int i = a[x].size() - 1; ~i; --i) {
    int y = a[x][i].first;
    int op = a[x][i].second;
    if (op == 1) {
      if (c[y] == 0 && !dfs(y, col))
        return 0;
      else if (c[y] != c[x])
        return 0;
    } else {
      if (c[y] == 0 && !dfs(y, 3 - col))
        return 0;
      else if (c[y] == c[x])
        return 0;
    }
  }
  return 1;
}
bool solve(char ch) {
  for (int i = 1; i <= n; ++i) a[i].clear(), c[i] = 0;
  for (int i = 1; i <= m; ++i) {
    int x = e[i].x;
    int y = e[i].y;
    if (e[i].ch == ch) {
      a[x].push_back(make_pair(y, 1));
      a[y].push_back(make_pair(x, 1));
    } else {
      a[x].push_back(make_pair(y, 0));
      a[y].push_back(make_pair(x, 0));
    }
  }
  tmp.clear();
  for (int i = 1; i <= n; ++i)
    if (!c[i]) {
      way[1].clear();
      way[2].clear();
      if (!dfs(i, 1)) return 0;
      if (way[1].size() > way[2].size()) swap(way[1], way[2]);
      tmp.insert(tmp.end(), way[1].begin(), way[1].end());
    }
  return 1;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= m; ++i) {
      scanf("%d%d %c", &e[i].x, &e[i].y, &e[i].ch);
    }
    bool flag = 0;
    if (solve('R')) {
      flag = 1;
      ans = tmp;
    }
    if (solve('B')) {
      if (!flag) {
        flag = 1;
        ans = tmp;
      } else if (tmp.size() < ans.size())
        ans = tmp;
    }
    if (!flag)
      puts("-1");
    else {
      printf("%d\n", ans.size());
      for (int i = ans.size() - 1; ~i; --i) printf("%d ", ans[i]);
      puts("");
    }
  }
  return 0;
}
