#include <bits/stdc++.h>
using namespace std;
template <class T>
bool remin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool remax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int nxt() {
  int first;
  scanf("%d", &first);
  return first;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
struct pt {
  long long first, second;
  pt() {}
  pt(long long first, long long second) : first(first), second(second) {}
  pt operator-(const pt &r) const {
    return pt(first - r.first, second - r.second);
  }
  pt operator+(const pt &r) const {
    return pt(first + r.first, second + r.second);
  }
  pt operator*(const long double &r) const { return pt(first * r, second * r); }
  long long sqlen() const { return abs(first * first + second * second); }
  long double len() const { return sqrtl(sqlen()); }
  bool operator<(const pt &r) const {
    if (fabs(first - r.first) > 1e-5) return first < r.first;
    return second < r.second;
  }
};
long long cross(const pt &l, const pt &r) {
  return l.first * r.second - l.second * r.first;
}
long long dot(const pt &l, const pt &r) {
  return l.first * r.first + l.second * r.second;
}
long long pwmod(long long a, long long n, long long mod) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret = ret * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ret;
}
const int N = 100 * 1000 + 10;
pair<int, int> e[N];
int w[N];
int n, m;
int p[N];
int sz[N];
void init(int n) {
  for (int i = 0; i < (int)(n); i++) {
    p[i] = i;
    sz[i] = 1;
  }
}
int get(int v) {
  if (v == p[v]) return v;
  return p[v] = get(p[v]);
}
bool unite(int a, int b) {
  a = get(a);
  b = get(b);
  if (a == b) return false;
  if (sz[a] < sz[b]) {
    swap(a, b);
  }
  p[b] = a;
  sz[a] += sz[b];
  return true;
}
vector<int> g[N];
pair<bool, vector<int> > solve1() {
  init(n);
  for (int i = 0; i < (int)(n); i++) {
    g[i].clear();
  }
  for (int i = 0; i < (int)(m); i++) {
    if (w[i] == 0) {
      unite(e[i].first, e[i].second);
    }
  }
  for (int i = 0; i < (int)(m); i++) {
    if (w[i] == 1) {
      int a = get(e[i].first);
      int b = get(e[i].second);
      g[a].push_back(b);
      g[b].push_back(a);
      if (a == b) {
        return make_pair(false, vector<int>());
      }
    }
  }
  vector<int> part(n, -1);
  vector<pair<vector<int>, vector<int> > > comps;
  for (int i = 0; i < (int)(n); i++) {
    int a = get(i);
    if (part[a] == -1) {
      pair<vector<int>, vector<int> > cur;
      queue<int> q;
      q.push(a);
      part[a] = 0;
      while (!q.empty()) {
        int v = q.front();
        q.pop();
        if (part[v]) {
          cur.second.push_back(v);
        } else {
          cur.first.push_back(v);
        }
        for (int to : g[v]) {
          if (part[to] == -1) {
            part[to] = part[v] ^ 1;
            q.push(to);
          } else {
            if (part[to] == part[v]) {
              return make_pair(false, vector<int>());
            }
          }
        }
      }
      comps.push_back(cur);
    }
  }
  vector<char> used(n, 0);
  for (auto cc : comps) {
    int szx = 0, szy = 0;
    for (int w : cc.first) {
      szx += sz[w];
    }
    for (int w : cc.second) {
      szy += sz[w];
    }
    vector<int> t;
    if (szx < szy) {
      t = cc.first;
    } else {
      t = cc.second;
    }
    for (int first : t) {
      used[first] = 1;
    }
  }
  vector<int> ans;
  for (int i = 0; i < (int)(n); i++) {
    if (used[get(i)]) {
      ans.push_back(i);
    }
  }
  return make_pair(true, ans);
}
inline void solve() {
  n = nxt();
  m = nxt();
  for (int i = 0; i < (int)(m); i++) {
    int a = nxt() - 1;
    int b = nxt() - 1;
    char s[3];
    scanf("%s", s);
    if (s[0] == 'R') {
      w[i] = 0;
    } else {
      w[i] = 1;
    }
    e[i] = make_pair(a, b);
  }
  auto ans1 = solve1();
  for (int i = 0; i < (int)(m); i++) {
    w[i] ^= 1;
  }
  auto ans2 = solve1();
  if (!ans1.first && !ans2.first) {
    cout << "-1\n";
    return;
  }
  vector<int> res = ans1.second;
  if (ans1.first && ans2.first) {
    if (ans1.second.size() < ans2.second.size()) {
      res = ans1.second;
    } else {
      res = ans2.second;
    }
  } else {
    if (ans1.first) {
      res = ans1.second;
    } else {
      res = ans2.second;
    }
  }
  cout << res.size() << "\n";
  for (int first : res) {
    cout << first + 1 << " ";
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
  cerr << "Time " << clock() / (double)CLOCKS_PER_SEC << endl;
  return 0;
}
