#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, inf = 1e9;
int n, m;
int mark[maxn], p[maxn], x;
vector<pair<int, int> > v[maxn];
int dfs(int a, bool c, int mid) {
  mark[a] = mid;
  p[a] = c;
  int sum = c;
  for (int i = 0; i < v[a].size(); i++) {
    int b = v[a][i].first, col = v[a][i].second;
    if (mark[b] != mid) {
      int r = dfs(b, (x ^ col ^ c), mid);
      if (r == inf) return inf;
      sum += r;
    } else {
      if ((x ^ col ^ c) != p[b]) return inf;
    }
  }
  return sum;
}
int solve(int a) {
  int a1 = dfs(a, 0, 1), a2 = dfs(a, 1, 2);
  int ans = min(a1, a2);
  if (ans == inf) return -1;
  if (ans == a1) {
    dfs(a, 0, 3);
  } else {
    dfs(a, 1, 4);
  }
  return ans;
}
int ss(bool ttt) {
  int ans = 0;
  x = ttt;
  for (int i = 0; i < n; i++) {
    if (!mark[i]) {
      int r = solve(i);
      if (r == -1) {
        return inf;
      }
      ans += r;
    }
  }
  return ans;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    char c;
    bool cc;
    cin >> a >> b >> c;
    cc = c == 'B';
    a--, b--;
    v[a].push_back(make_pair(b, cc));
    v[b].push_back(make_pair(a, cc));
  }
  fill(mark, mark + maxn, 0);
  int ans1 = ss(0);
  fill(mark, mark + maxn, 0);
  int ans2 = ss(1);
  int ans = min(ans1, ans2);
  if (ans == inf) {
    cout << "-1\n";
    return 0;
  }
  if (ans == ans1) {
    fill(mark, mark + maxn, 0);
    ss(0);
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) {
    if (p[i]) cout << i + 1 << ' ';
  }
}
