#include <bits/stdc++.h>
using namespace std;
bool dfs(int u, vector<vector<pair<int, char> > > &v, vector<int> &m,
         char color, int &curGood, int &curBad, vector<int> &touched) {
  bool good = true;
  if (m[u] == 1)
    curGood++;
  else if (m[u] == 0)
    curBad++;
  touched.push_back(u);
  for (int i = 0; i < v[u].size(); i++) {
    int n = v[u][i].first;
    int c = v[u][i].second;
    if (m[n] != -1) {
      bool res;
      if (m[n] && m[u]) {
        res = c == color;
      } else if (m[n] || m[u]) {
        res = c != color;
      } else {
        res = c == color;
      }
      if (!res) return false;
      continue;
    }
    if ((c == color && m[u] == 0) || (c != color && m[u] == 1)) {
      m[n] = 0;
    } else {
      m[n] = 1;
    }
    bool g = dfs(n, v, m, color, curGood, curBad, touched);
    good = good && g;
  }
  return good;
}
vector<int> solve(vector<vector<pair<int, char> > > &v, char color,
                  bool &valid) {
  vector<int> m(v.size(), -1);
  bool good = true;
  for (int i = 0; i < v.size(); i++) {
    if (m[i] == -1) {
      int curGood = 0;
      int curBad = 0;
      vector<int> touched;
      m[i] = 0;
      bool g = dfs(i, v, m, color, curGood, curBad, touched);
      good = good && g;
      if (curBad < curGood) {
        for (int j = 0; j < touched.size(); j++) m[touched[j]] ^= 1;
      }
    }
  }
  valid = good;
  return m;
}
int main() {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<pair<int, char> > row;
  vector<vector<pair<int, char> > > v(N, row);
  for (int i = 0; i < M; i++) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    a--;
    b--;
    v[a].push_back(make_pair(b, c));
    v[b].push_back(make_pair(a, c));
  }
  bool rValid, bValid;
  vector<int> r = solve(v, 'R', rValid);
  vector<int> b = solve(v, 'B', bValid);
  int rCount = 0;
  int bCount = 0;
  for (int i = 0; i < r.size(); i++) {
    if (r[i]) rCount++;
  }
  for (int i = 0; i < b.size(); i++) {
    if (b[i]) bCount++;
  }
  rCount = min(rCount, (int)(r.size() - rCount));
  bCount = min(bCount, (int)(b.size() - bCount));
  if (!rValid && !bValid) {
    cout << "-1\n" << endl;
    return 0;
  } else if (rValid && !bValid) {
    cout << rCount << "\n";
    for (int i = 0; i < r.size(); i++) {
      if (r[i] == (rCount < r.size() - rCount)) cout << i + 1 << " ";
    }
  } else if (bValid && !rValid) {
    cout << bCount << "\n";
    for (int i = 0; i < b.size(); i++) {
      if (b[i] == (bCount < b.size() - bCount)) cout << i + 1 << " ";
    }
  } else if (rCount < bCount) {
    cout << rCount << "\n";
    for (int i = 0; i < r.size(); i++) {
      if (r[i] == (rCount < r.size() - rCount)) cout << i + 1 << " ";
    }
  } else {
    cout << bCount << "\n";
    for (int i = 0; i < b.size(); i++) {
      if (b[i] == (bCount < b.size() - bCount)) cout << i + 1 << " ";
    }
  }
  cout << "\n";
}
