#include <bits/stdc++.h>
using namespace std;
int n, m, ans, ones, zeroes, value, f;
int vis[100001], assign[100001];
vector<pair<int, int> > v[100001];
vector<int> res, change, comp;
void dfs(int cur) {
  comp.push_back(cur);
  vis[cur] = 1;
  if (assign[cur] == 1)
    ones++;
  else
    zeroes++;
  for (int i = 0; i < v[cur].size(); i++) {
    int x = v[cur][i].first;
    int y = v[cur][i].second;
    if (assign[x] == -1) {
      if (y == value)
        assign[x] = assign[cur];
      else
        assign[x] = 1 - assign[cur];
    } else {
      if (y == value) {
        if (assign[x] != assign[cur]) {
          f = 1;
          return;
        }
      } else {
        if (assign[x] == assign[cur]) {
          f = 1;
          return;
        }
      }
    }
    if (!vis[x]) dfs(x);
  }
}
void check(int val) {
  value = val;
  res.clear();
  for (int i = 1; i <= n; i++) {
    assign[i] = -1;
    vis[i] = 0;
  }
  int got = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    comp.clear();
    ones = 0;
    zeroes = 0;
    assign[i] = 1;
    f = 0;
    dfs(i);
    if (f == 0) {
      got += min(ones, zeroes);
      if (ones < zeroes) {
        for (auto it : comp) {
          if (assign[it] == 1) res.push_back(it);
        }
      } else {
        for (auto it : comp) {
          if (assign[it] == 0) res.push_back(it);
        }
      }
    } else
      return;
  }
  if (got < ans) {
    ans = got;
    change.clear();
    for (auto it : res) change.push_back(it);
  }
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  int i, j, x, y;
  char ch;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> x >> y >> ch;
    if (ch == 'B') {
      v[x].push_back(make_pair(y, 0));
      v[y].push_back(make_pair(x, 0));
    } else {
      v[x].push_back(make_pair(y, 1));
      v[y].push_back(make_pair(x, 1));
    }
  }
  ans = 100000000;
  check(0);
  check(1);
  if (ans == 100000000) {
    cout << "-1";
    return 0;
  }
  cout << ans << "\n";
  for (auto it : change) cout << it << " ";
  return 0;
}
