#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7, INF = 1e9;
int u[N], v[N], c[N], color[N], p[N], sz[N], tkkn[N];
vector<int> adj[N];
int find(int x) { return p[x] = (p[x] == x) ? p[x] : find(p[x]); }
void merge(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) {
    return;
  }
  p[x] = y;
  sz[y] += sz[x];
}
int dfs(int u, int col, vector<int> &a) {
  if (~color[u]) {
    if (col ^ color[u]) {
      return 0;
    }
    return 1;
  }
  a.push_back(u);
  color[u] = col;
  for (int v : adj[u]) {
    if (!dfs(v, col ^ 1, a)) {
      return 0;
    }
  }
  return 1;
}
pair<int, vector<int> > solve(int n, int m, int g) {
  for (int i = 1; i <= n; i++) {
    p[i] = i;
    color[i] = -1;
    sz[i] = 1;
    adj[i].clear();
    tkkn[i] = 0;
  }
  for (int i = 1; i <= m; i++) {
    c[i] ^= g;
  }
  for (int i = 1; i <= m; i++) {
    if (c[i] ^ 1) {
      merge(v[i], u[i]);
    }
  }
  for (int i = 1; i <= m; i++) {
    if (c[i] && find(v[i]) == find(u[i])) {
      return {INF, vector<int>()};
    }
    if (c[i]) {
      adj[find(u[i])].push_back(find(v[i]));
      adj[find(v[i])].push_back(find(u[i]));
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (find(i) == i && color[i] == -1) {
      vector<int> a;
      if (!dfs(i, 0, a)) {
        return {INF, vector<int>()};
      }
      int x = 0, y = 0;
      for (int z : a) {
        if (color[z])
          x += sz[z];
        else
          y += sz[z];
      }
      ans += min(x, y);
      for (int z : a) {
        if (x <= y) {
          tkkn[z] = color[z];
        } else {
          tkkn[z] = !color[z];
        }
      }
    }
  }
  vector<int> aa;
  for (int i = 1; i <= n; i++)
    if (tkkn[find(i)]) {
      aa.push_back(i);
    }
  return make_pair(ans, aa);
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    char ch;
    cin >> u[i] >> v[i] >> ch;
    c[i] = (ch == 'B');
  }
  int ans;
  vector<int> v;
  tie(ans, v) = min(solve(n, m, 1), solve(n, m, 1));
  if (ans > n) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  for (int x : v) {
    cout << x << " ";
  }
  cout << endl;
}
