#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
vector<vector<pair<int, int> > > adj;
vector<vector<int> > vis;
vector<bool> flag(2, false);
vector<vector<int> > cnt(2, vector<int>(0, 0));
void dfs(int u, int p, int type) {
  if (flag[type]) return;
  vis[type][u] = p;
  cnt[p].push_back(u);
  for (int j = 0; j < (int)adj[u].size(); j++) {
    int v = adj[u][j].first;
    int t = adj[u][j].second;
    if (vis[type][v] == -1) {
      if (t == type) {
        dfs(v, p, type);
      } else {
        dfs(v, 1 - p, type);
      }
    } else {
      if (t == type) {
        if (vis[type][v] != vis[type][u]) flag[type] = true;
      } else {
        if (vis[type][v] == vis[type][u]) flag[type] = true;
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  adj.assign(n, vector<pair<int, int> >(0));
  for (int i = 0; i < m; i++) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    x--;
    y--;
    int t = -1;
    if (c == 'B') t = 0;
    if (c == 'R') t = 1;
    adj[x].push_back(pair<int, int>(y, t));
    adj[y].push_back(pair<int, int>(x, t));
  }
  vis.assign(2, vector<int>(n, -1));
  vector<vector<int> > re(2, vector<int>(0, 0));
  for (int type = 0; type < 2; type++) {
    for (int u = 0; u < n; u++) {
      if (vis[type][u] == -1) {
        cnt.assign(2, vector<int>(0, 0));
        dfs(u, 0, type);
        if (flag[type]) break;
        if (cnt[0].size() < cnt[1].size()) {
          for (int i = 0; i < (int)cnt[0].size(); i++) {
            re[type].push_back(cnt[0][i]);
          }
        } else {
          for (int i = 0; i < (int)cnt[1].size(); i++)
            re[type].push_back(cnt[1][i]);
        }
      }
    }
  }
  int ans = 1000000000;
  int type = 0;
  for (int i = 0; i < 2; i++) {
    if (!flag[i]) {
      if (ans > (int)re[i].size()) {
        ans = (int)re[i].size();
        type = i;
      }
    }
  }
  if (ans == 1000000000) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
    for (int i = 0; i < (int)re[type].size(); i++) {
      cout << re[type][i] + 1 << " ";
    }
  }
  return 0;
}
