#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100100];
int b[100100];
int c[100100];
vector<int> p[100100];
vector<int> ch[100100];
int per[100100];
int sz[100100];
int pr(int x) {
  if (per[x] == x) return x;
  return per[x] = pr(per[x]);
}
int v[100100];
vector<int> rr[4];
bool dfs(int x, int col = 1) {
  if (v[x]) {
    return col == v[x];
  }
  for (int i = 0; i < ch[x].size(); i++) {
    rr[col].push_back(ch[x][i]);
  }
  v[x] = col;
  for (int i = 0; i < p[x].size(); i++) {
    if (!dfs(p[x][i], col ^ 3)) return 0;
  }
  return 1;
}
vector<int> ch1(char c1) {
  for (int i = 1; i <= n; i++) {
    per[i] = i;
    p[i].clear();
    ch[i].clear();
    sz[i] = 1;
    v[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    if (c[i] == c1) continue;
    int x = pr(a[i]);
    int y = pr(b[i]);
    if (x == y) continue;
    if (sz[x] < sz[y]) swap(x, y);
    per[y] = x;
    sz[x] += sz[y];
  }
  for (int i = 0; i < m; i++) {
    if (c[i] != c1) continue;
    p[pr(a[i])].push_back(pr(b[i]));
    p[pr(b[i])].push_back(pr(a[i]));
  }
  for (int i = 1; i <= n; i++) {
    ch[pr(i)].push_back(i);
  }
  vector<int> err;
  vector<int> res;
  for (int i = 0; i <= n; i++) err.push_back(-1);
  for (int i = 1; i <= n; i++) {
    if (v[pr(i)]) continue;
    rr[1].clear();
    rr[2].clear();
    bool b = dfs(pr(i));
    if (!b) return err;
    if (rr[1].size() <= rr[2].size()) {
      for (int j = 0; j < rr[1].size(); j++) {
        res.push_back(rr[1][j]);
      }
    } else {
      for (int j = 0; j < rr[2].size(); j++) {
        res.push_back(rr[2][j]);
      }
    }
  }
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    scanf("%d%d %c", &a[i], &b[i], &c[i]);
  }
  vector<int> res1 = ch1('R');
  vector<int> res = ch1('B');
  if (res.size() > res1.size()) {
    swap(res, res1);
  }
  if (res.size() > n) {
    cout << -1;
    return 0;
  }
  cout << res.size() << endl;
  for (int i = 0; i < res.size(); i++) printf("%d ", res[i]);
  return 0;
}
