#include <bits/stdc++.h>
using namespace std;
vector<pair<int, char> > adj[100100];
bool vis[100100];
vector<int> vis2;
int st[100100];
int quit;
void flood(int vtx, char color) {
  for (int i = 0; i < adj[vtx].size(); ++i) {
    int nxt = adj[vtx][i].first;
    int expect = (adj[vtx][i].second != color) ? (3 - st[vtx]) : st[vtx];
    if (st[nxt] != 0 && st[nxt] != expect) {
      quit = 1;
      return;
    }
    st[nxt] = expect;
    if (!vis[nxt]) {
      vis[nxt] = true;
      vis2.push_back(nxt);
      flood(nxt, color);
      if (quit) return;
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    --a;
    --b;
    adj[a].push_back(pair<int, char>(b, c));
    adj[b].push_back(pair<int, char>(a, c));
  }
  int ans = 1e8;
  vector<int> seq;
  for (int x = 0; x < 2; ++x) {
    quit = 0;
    int ans1 = 0;
    memset(st, 0, sizeof(st));
    memset(vis, 0, sizeof(vis));
    vis2.clear();
    char color = (x == 0) ? 'R' : 'B';
    vector<int> seq1;
    for (int i = 0; i < n; ++i) {
      vis2.clear();
      if (!vis[i]) {
        vis[i] = true;
        vis2.push_back(i);
        st[i] = 1;
        flood(i, color);
      }
      if (quit) break;
      int s = 0, t = 0;
      vector<int> ss, ts;
      for (int j = 0; j < vis2.size(); ++j) {
        if (st[vis2[j]] == 1) {
          ++s;
          ss.push_back(vis2[j]);
        } else if (st[vis2[j]] == 2) {
          ++t;
          ts.push_back(vis2[j]);
        }
      }
      ans1 += min(s, t);
      if (s < t) {
        for (int j = 0; j < ss.size(); ++j) {
          seq1.push_back(ss[j]);
        }
      } else {
        for (int j = 0; j < ts.size(); ++j) {
          seq1.push_back(ts[j]);
        }
      }
    }
    if (!quit) {
      if (ans1 < ans) {
        ans = ans1;
        seq = seq1;
      }
    }
  }
  if (ans == 1e8)
    cout << "-1\n";
  else {
    cout << ans << '\n';
    for (int i = 0; i < seq.size(); ++i) {
      cout << seq[i] + 1 << ' ';
    }
    cout << '\n';
  }
}
