#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
char c;
int n, m;
int u, v;
int par[N];
int a, b, d;
int vis[N];
bool pos = 1;
vector<int> tmp[2];
vector<vector<pair<int, int> > > g(N);
void dfs(int x, int p) {
  vis[x] = 1 + p;
  b++;
  for (auto it : g[x]) {
    if (it.second == 1 - p and it.first != par[x]) {
      if (vis[it.first] - 1 == u) {
        pos = 0;
        return;
      } else if (vis[it.first] == 0) {
        par[it.first] = x;
        tmp[1].push_back(it.first);
        dfs(it.first, 1 - u);
        a++;
      }
    } else {
      if (!vis[it.first]) {
        par[it.first] = x;
        tmp[0].push_back(it.first);
        dfs(it.first, u);
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> c;
    d = (c == 'B');
    g[u].push_back(make_pair(v, d));
    g[v].push_back(make_pair(u, d));
  }
  int ans1 = 0, ans2 = 0;
  set<int> s1, s2;
  par[1] = -1;
  u = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      a = b = 0;
      tmp[0].clear();
      tmp[1].clear();
      tmp[0].push_back(i);
      dfs(i, u);
      if (!pos) {
        ans1 = INT_MAX;
        break;
      } else {
        if (a <= b - a)
          s1.insert(tmp[1].begin(), tmp[1].end());
        else
          s1.insert(tmp[0].begin(), tmp[0].end());
        ans1 += min(a, b - a);
      }
    }
  }
  memset(vis, 0, sizeof(vis));
  pos = 1;
  u = 1;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      a = b = 0;
      tmp[0].clear();
      tmp[1].clear();
      tmp[0].push_back(i);
      dfs(i, u);
      if (!pos) {
        ans2 = INT_MAX;
        break;
      } else {
        if (a <= b - a)
          s2.insert(tmp[1].begin(), tmp[1].end());
        else
          s2.insert(tmp[0].begin(), tmp[0].end());
        ans2 += min(a, b - a);
      }
    }
  }
  int ans = min(ans1, ans2);
  if (ans == INT_MAX) ans = -1;
  printf("%d\n", ans);
  if (ans != -1) {
    if (ans1 < ans2) {
      for (auto it : s1) printf("%d ", it);
    } else {
      for (auto it : s2) printf("%d ", it);
    }
    printf("%s\n", "");
  }
}
