#include <bits/stdc++.h>
using namespace std;
void rs(int &x) { scanf("%d", &x); }
void rsl(long long &x) { scanf("%I64d", &x); }
void rsd(double &x) { scanf("%lf", &x); }
void rss(char *str) { scanf("%s", str); }
void ws(int &x) { printf("%d ", x); }
void wsl(long long &x) { printf("%I64d ", x); }
void wsd(double &x) { printf("%lf ", x); }
void wss(char *str) { printf("%s ", str); }
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int const N = (1e5) + 5;
int const mod = (1e9) + 7;
vector<pair<int, char>> gr[N];
vector<int> red_ans, blue_ans, t, sr;
int Colour[N];
char let;
bool dfs(int v, int ind) {
  if (Colour[v] > 0) {
    bool var = (Colour[v] == ind);
    return var;
  }
  bool flag = true;
  Colour[v] = ind;
  if (ind == 1) {
    t.push_back(v);
  } else {
    sr.push_back(v);
  }
  for (int i = 0; i < gr[v].size(); ++i) {
    if (gr[v][i].second == let) {
      flag &= dfs(gr[v][i].first, ind);
    } else {
      flag &= dfs(gr[v][i].first, (ind % 2) + 1);
    }
  }
  return flag;
}
void show(vector<int> &var) {
  cout << var.size() << endl;
  for (int i = 0; i < var.size(); ++i) {
    int x = var[i] + 1;
    ws(x);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int v, u;
    char col;
    rs(v);
    rs(u);
    cin >> col;
    v--;
    u--;
    gr[v].push_back(make_pair(u, col));
    gr[u].push_back(make_pair(v, col));
  }
  let = 'R';
  bool fl = true;
  for (int i = 0; i < n; ++i) {
    if (gr[i].size() > 0 && Colour[i] == 0) {
      fl &= dfs(i, 1);
      if (t.size() < sr.size()) {
        for (int i = 0; i < t.size(); ++i) {
          red_ans.push_back(t[i]);
        }
      } else {
        for (int i = 0; i < sr.size(); ++i) {
          red_ans.push_back(sr[i]);
        }
      }
      t.clear();
      sr.clear();
    }
  }
  memset(Colour, 0, sizeof(Colour));
  let = 'B';
  bool fl2 = true;
  for (int i = 0; i < n; ++i) {
    if (gr[i].size() > 0 && Colour[i] == 0) {
      fl2 &= dfs(i, 1);
      if (t.size() < sr.size()) {
        for (int i = 0; i < t.size(); ++i) {
          blue_ans.push_back(t[i]);
        }
      } else {
        for (int i = 0; i < sr.size(); ++i) {
          blue_ans.push_back(sr[i]);
        }
      }
      t.clear();
      sr.clear();
    }
  }
  if (fl && fl2) {
    if (red_ans.size() < blue_ans.size()) {
      show(red_ans);
    } else {
      show(blue_ans);
    }
  } else if (fl) {
    show(red_ans);
  } else if (fl2) {
    show(blue_ans);
  } else {
    cout << "-1";
    return 0;
  }
  return 0;
}
