#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
void Maximize(T &x, U y) {
  if (x < y) {
    x = y;
  }
}
template <typename T, typename U>
void Minimize(T &x, U y) {
  if (x > y) {
    x = y;
  }
}
template <typename T>
int Sign(const T &x) {
  return (x < 0 ? -1 : (x == 0 ? 0 : +1));
}
const int N = 100005;
int n;
int m;
vector<pair<int, bool>> G[N];
vector<int> Set[2];
int Color[N];
void bipartiteDfs(int x, bool Col, bool colSrc, bool &goodSol) {
  Color[x] = Col;
  Set[Col].push_back(x);
  for (pair<int, bool> &Edge : G[x]) {
    int y;
    bool t;
    tie(y, t) = Edge;
    if (t == colSrc) {
      if (Color[y] == -1) {
        bipartiteDfs(y, Col ^ 1, colSrc, goodSol);
      } else {
        if (Color[y] == Color[x]) {
          goodSol = false;
        }
      }
    } else {
      if (Color[y] == -1) {
        bipartiteDfs(y, Col, colSrc, goodSol);
      } else {
        if (Color[y] != Color[x]) {
          goodSol = false;
        }
      }
    }
  }
}
pair<bool, vector<int>> Solve(bool colSrc) {
  fill(Color, Color + N, -1);
  bool isSol = true;
  vector<int> Sol;
  for (int i = 1; i <= n; i++) {
    if (Color[i] == -1) {
      for (int j = 0; j < 2; j++) Set[j].clear();
      bipartiteDfs(i, 0, colSrc, isSol);
      if (Set[0].size() > Set[1].size()) swap(Set[0], Set[1]);
      Sol.insert(Sol.end(), Set[0].begin(), Set[0].end());
    }
  }
  return {isSol, Sol};
}
int main() {
  cin.tie(nullptr);
  ios_base ::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    char c;
    int x, y;
    cin >> x >> y >> c;
    c = (c == 'B' ? 0 : 1);
    G[x].emplace_back(y, c);
    G[y].emplace_back(x, c);
  }
  pair<bool, vector<int>> fiSol = Solve(true);
  pair<bool, vector<int>> seSol = Solve(false);
  if (fiSol.first == false) {
    swap(fiSol, seSol);
  }
  if (fiSol.first == false) {
    cout << "-1\n";
  } else {
    if (seSol.first == false) {
      cout << fiSol.second.size() << "\n";
      for (int x : fiSol.second) cout << x << " ";
    } else {
      if (fiSol.second.size() > seSol.second.size()) {
        swap(fiSol, seSol);
      }
      cout << fiSol.second.size() << "\n";
      for (int x : fiSol.second) cout << x << " ";
    }
  }
  return 0;
}
