#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int MAXN = 100100;
int n, m;
struct edge {
  int u, v, lnk, typ;
  edge() {}
  edge(int u, int v, int lnk, int typ) : u(u), v(v), lnk(lnk), typ(typ) {}
  bool operator<(const edge oth) const {
    if (u < oth.u) return true;
    return false;
  }
};
edge ed[2 * MAXN], ed1[2 * MAXN];
int st[MAXN], fn[MAXN];
int ln[MAXN], was[MAXN];
vector<int> fail;
int qq[MAXN], s, en;
bool bfs(int u) {
  for (int i = st[u]; i <= fn[u]; ++i) {
    int to = ed[i].v;
    if (was[to] == -1) {
      was[to] = was[u] ^ ed[i].typ;
      qq[en++] = to;
    } else {
      if (was[to] ^ ed[i].typ != was[u]) return false;
    }
  }
  return true;
}
vector<int> res() {
  memset(was, -1, sizeof was);
  vector<int> ans;
  for (int i = 0; i < n; ++i) {
    if (was[i] != -1) continue;
    s = 0, en = 0;
    qq[en++] = i;
    was[i] = 0;
    while (s != en) {
      if (!bfs(qq[s++])) return fail;
    }
    int ms[2] = {0, 0};
    for (int i = 0; i < en; ++i) {
      ms[was[qq[i]]]++;
    }
    int q = 0;
    if (ms[1] < ms[0]) q = 1;
    for (int i = 0; i < en; ++i)
      if (was[qq[i]] == q) ans.push_back(qq[i]);
  }
  ans.push_back(ans.size());
  return ans;
}
void solve() {
  cin >> n >> m;
  fail.push_back(1e9);
  for (int i = 0; i < m; ++i) {
    int u, v;
    char k;
    cin >> u >> v >> k;
    u--, v--;
    ed[i] = edge(u, v, i, k == 'R');
    ed[i + m] = edge(v, u, i, k == 'R');
  }
  sort(ed, ed + 2 * m);
  memset(ln, -1, sizeof ln);
  st[ed[0].u] = 0;
  ln[ed[0].lnk] = 0;
  for (int i = 1; i < 2 * m; ++i) {
    if (ln[ed[i].lnk] == -1) {
      ln[ed[i].lnk] = i;
    } else {
      ed[i].lnk = ln[ed[i].lnk];
      ed[ed[i].lnk].lnk = i;
    }
    if (ed[i].u == ed[i - 1].u) continue;
    fn[ed[i - 1].u] = i - 1;
    st[ed[i].u] = i;
  }
  fn[ed[2 * m - 1].u] = 2 * m - 1;
  vector<int> a, b;
  for (int i = 0; i < 2 * m; ++i) {
    ed1[i] = ed[i];
    ed1[i].typ ^= 1;
  }
  a = res();
  for (int i = 0; i < 2 * m; ++i) ed[i] = ed1[i];
  b = res();
  if (a.back() > b.back()) a = b;
  if (a.back() == 1e9) {
    cout << -1;
    return;
  }
  cout << a.size() - 1 << endl;
  for (int i = 0; i < a.size() - 1; ++i) cout << a[i] + 1 << ' ';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(1313);
  int t;
  solve();
  return 0;
}
