#include <bits/stdc++.h>
using namespace std;
bool SR(int &x) { return scanf("%d", &x) == 1; }
bool SR(long long &x) { return scanf("%lld", &x) == 1; }
bool SR(double &x) { return scanf("%lf", &x) == 1; }
bool SR(char *s) { return scanf("%s", s) == 1; }
bool RI() { return true; }
template <typename I, typename... T>
bool RI(I &x, T &...tail) {
  return SR(x) && RI(tail...);
}
void SP(const int x) { printf("%d", x); }
void SP(const long long x) { printf("%lld", x); }
void SP(const double x) { printf("%.16lf", x); }
void SP(const char *s) { printf("%s", s); }
void PL() { puts(""); }
template <typename I, typename... T>
void PL(const I x, const T... tail) {
  SP(x);
  if (sizeof...(tail)) putchar(' ');
  PL(tail...);
}
const int maxn = 4e5 + 5;
int n, m;
int f[maxn], c[maxn];
vector<int> id[maxn];
void read() {
  RI(n, m);
  for (int i = (1); i <= int(m); i++) {
    int a, b;
    char s[2];
    RI(a, b, s);
    f[i] = a ^ b;
    c[i] = (s[0] == 'B');
    id[a].push_back(i);
    id[b].push_back(i);
  }
}
int to(int u, int i) { return u ^ f[i]; }
int g[maxn];
vector<int> has[maxn];
bitset<maxn> vis;
void dfs1(int u, int p) {
  g[u] = p;
  vis[u] = 1;
  has[p].push_back(u);
  for (auto i : id[u])
    if (!vis[to(u, i)]) dfs1(to(u, i), p);
}
void build() {
  for (int i = (1); i <= int(n); i++)
    if (!vis[i]) dfs1(i, i);
}
int par[maxn << 1];
int find(int u) { return u == par[u] ? u : par[u] = find(par[u]); }
void merge(int a, int b) { par[find(a)] = find(b); }
vector<int> doo(int src) {
  for (auto u : has[src]) par[u << 1] = u << 1, par[u << 1 | 1] = u << 1 | 1;
  for (auto u : has[src])
    for (auto i : id[u]) {
      merge(u << 1, (to(u, i) << 1) ^ c[i]);
      merge(u << 1 | 1, (to(u, i) << 1) ^ c[i] ^ 1);
    }
  if (find(src << 1) == find(src << 1 | 1)) return vector<int>(1, -1);
  int cnt = 0;
  for (auto u : has[src]) cnt += (find(u << 1) == find(src << 1));
  if (cnt < ((int)(has[src]).size()) - cnt) {
    vector<int> ans;
    for (auto u : has[src])
      if (find(u << 1) == find(src << 1)) ans.push_back(u);
    return ans;
  } else {
    vector<int> ans;
    for (auto u : has[src])
      if (find(u << 1 | 1) == find(src << 1)) ans.push_back(u);
    return ans;
  }
}
void sol() {
  vector<int> ans1, ans2;
  for (int i = (1); i <= int(n); i++)
    if (g[i] == i) {
      vector<int> sub = doo(i);
      ans1.insert(ans1.end(), (sub).begin(), (sub).end());
    }
  sort((ans1).begin(), (ans1).end());
  for (int i = (1); i <= int(m); i++) c[i] ^= 1;
  for (int i = (1); i <= int(n); i++)
    if (g[i] == i) {
      vector<int> sub = doo(i);
      ans2.insert(ans2.end(), (sub).begin(), (sub).end());
    }
  sort((ans2).begin(), (ans2).end());
  if (((int)(ans1).size()) && ans1[0] == -1 && ((int)(ans2).size()) &&
      ans2[0] == -1) {
    PL(-1);
    return;
  }
  if (((int)(ans1).size()) > ((int)(ans2).size())) ans1.swap(ans2);
  auto &ans = (((int)(ans1).size()) && ans1[0] == -1 ? ans2 : ans1);
  PL(((int)(ans).size()));
  for (int i = 0; i < int(((int)(ans).size())); i++)
    printf("%d%c", ans[i], " \n"[i == ((int)(ans).size()) - 1]);
}
int main() {
  read();
  build();
  sol();
  return 0;
}
