#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int N = 234567;
int v, id, h, n, m, i, ro, qh, qt, q, w;
bool done[N];
int qq[N], x[N], y[N], col[N], inv[N], lv[N];
vector<pair<int, int> > g[N];
int z[N][2][2];
char ch;
vector<int> st[N][2][2];
vector<int> ve, an, ee, roots;
bool can, solved;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d %c", &x[i], &y[i], &ch);
    col[i] = (ch == 'B');
    g[x[i]].push_back(make_pair(y[i], i));
    g[y[i]].push_back(make_pair(x[i], i));
  }
  for (int i = 1; i <= n; i++)
    z[i][0][0] = z[i][0][1] = z[i][1][0] = z[i][1][1] = 1e9;
  for (int q = 0; q <= 1; q++)
    for (int w = 0; w <= 1; w++) {
      memset(inv, 0, sizeof(inv));
      memset(done, 0, sizeof(done));
      memset(lv, 0, sizeof(lv));
      roots.clear();
      for (int i = 1; i <= n; i++)
        if (!done[i]) {
          roots.push_back(i);
          ve.clear();
          ro = i;
          done[ro] = 1;
          if (w) {
            inv[ro] = 1;
            ve.push_back(ro);
          }
          qq[qh = qt = 1] = ro;
          while (qh <= qt) {
            v = qq[qh++];
            for (int j = 0; j <= ((int)(g[v]).size()) - 1; j++) {
              h = g[v][j].first;
              id = g[v][j].second;
              if (done[h]) continue;
              done[h] = 1;
              qq[++qt] = h;
              if ((col[id] ^ inv[v]) != q) {
                inv[h] = 1;
                ve.push_back(h);
              }
            }
          }
          solved = 1;
          qq[qh = qt = 1] = ro;
          lv[ro] = i;
          while (qh <= qt) {
            v = qq[qh++];
            lv[v] = i;
            for (int j = 0; j <= ((int)(g[v]).size()) - 1; j++) {
              h = g[v][j].first;
              id = g[v][j].second;
              if ((col[id] ^ inv[v] ^ inv[h]) != q) solved = 0;
              if (lv[h] < i) {
                lv[h] = i;
                qq[++qt] = h;
              }
            }
          }
          if (solved) {
            z[ro][q][w] = ((int)(ve).size());
            st[ro][q][w] = ve;
          }
        }
    }
  an.push_back(-1);
  for (int q = 0; q <= 1; q++) {
    can = 1;
    for (int j = 0; j <= ((int)(roots).size()) - 1; j++)
      if (min(z[roots[j]][q][0], z[roots[j]][q][1]) == 1e9) {
        can = 0;
        break;
      }
    if (!can) continue;
    ee.clear();
    for (int j = 0; j <= ((int)(roots).size()) - 1; j++)
      if (z[roots[j]][q][0] < z[roots[j]][q][1]) {
        for (int i = 0; i <= ((int)(st[roots[j]][q][0]).size()) - 1; i++)
          ee.push_back(st[roots[j]][q][0][i]);
      } else {
        for (int i = 0; i <= ((int)(st[roots[j]][q][1]).size()) - 1; i++)
          ee.push_back(st[roots[j]][q][1][i]);
      }
    if (an.back() == -1 || ((int)(ee).size()) < ((int)(an).size())) an = ee;
  }
  if (an.back() == -1)
    puts("-1");
  else {
    printf("%d\n", ((int)(an).size()));
    for (int i = 0; i <= ((int)(an).size()) - 1; i++) printf("%d ", an[i]);
  }
  return 0;
}
