#include <bits/stdc++.h>
using namespace std;
struct aj {
  int i;
  int n;
  aj(int a, int b) {
    i = a;
    n = b;
  }
};
vector<aj> adj[100005];
queue<int> way[5], rst, bst, qeds;
bool qryed[100005] = {false}, qed[100005] = {false}, ochn[100005] = {false},
     sb = false, sr = false;
int clr[100005] = {0}, n, m, i, a, b;
char col[3] = {'\0'};
int qry(int nod, int chn, int tgc, int stk) {
  qryed[nod] = true;
  int ret = 1;
  if (qed[nod] == true) {
    if (ochn[nod] == chn)
      return 1;
    else
      return -1;
  }
  qed[nod] = true;
  qeds.push(nod);
  if (chn == 1) {
    way[stk].push(nod);
    ochn[nod] = true;
  }
  for (vector<aj>::iterator it = adj[nod].begin(); it != adj[nod].end(); it++) {
    if (clr[it->i] != tgc && chn == 1) {
      ret = min(ret, qry(it->n, 0, tgc, stk));
    } else if (clr[it->i] != tgc && chn != 1) {
      ret = min(ret, qry(it->n, 1, tgc, stk));
    } else if (clr[it->i] == tgc && chn == 1) {
      ret = min(ret, qry(it->n, 1, tgc, stk));
    } else if (clr[it->i] == tgc && chn != 1) {
      ret = min(ret, qry(it->n, 0, tgc, stk));
    }
  }
  return ret;
}
int main() {
  scanf("%d %d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d %s", &a, &b, col);
    if (col[0] == 'R')
      clr[i] = 1;
    else if (col[0] == 'B')
      clr[i] = -1;
    adj[a].push_back(aj(i, b));
    adj[b].push_back(aj(i, a));
  }
  int r1, r2, r3, r4, ans, sz, t1;
  for (i = 1; i <= n; i++) {
    if (qryed[i] == false) {
      r1 = qry(i, 1, 1, 1);
      while (!qeds.empty()) {
        t1 = qeds.front();
        qed[t1] = false;
        ochn[t1] = false;
        qeds.pop();
      }
      r2 = qry(i, 0, 1, 2);
      while (!qeds.empty()) {
        t1 = qeds.front();
        qed[t1] = false;
        ochn[t1] = false;
        qeds.pop();
      }
      ans = 0, sz = 1000000;
      if (r1 != -1 && way[1].size() < sz) {
        sz = way[1].size();
        ans = 1;
      }
      if (r2 != -1 && way[2].size() < sz) {
        sz = way[2].size();
        ans = 2;
      }
      if (ans == 0) sr = true;
      while (!way[ans].empty()) {
        rst.push(way[ans].front());
        way[ans].pop();
      }
      while (!way[1].empty()) way[1].pop();
      while (!way[2].empty()) way[2].pop();
    }
  }
  for (i = 1; i <= n; i++) qryed[i] = false;
  for (i = 1; i <= n; i++) {
    if (qryed[i] == false) {
      r3 = qry(i, 1, -1, 3);
      while (!qeds.empty()) {
        t1 = qeds.front();
        qed[t1] = false;
        ochn[t1] = false;
        qeds.pop();
      }
      r4 = qry(i, 0, -1, 4);
      while (!qeds.empty()) {
        t1 = qeds.front();
        qed[t1] = false;
        ochn[t1] = false;
        qeds.pop();
      }
      ans = 0, sz = 1000000;
      if (r3 != -1 && way[3].size() < sz) {
        sz = way[3].size();
        ans = 3;
      }
      if (r4 != -1 && way[4].size() < sz) {
        sz = way[4].size();
        ans = 4;
      }
      if (ans == 0) sb = true;
      while (!way[ans].empty()) {
        bst.push(way[ans].front());
        way[ans].pop();
      }
      while (!way[3].empty()) way[3].pop();
      while (!way[4].empty()) way[4].pop();
    }
  }
  if (sb == true && sr == true) {
    printf("-1");
    return 0;
  }
  if ((rst.size() <= bst.size() && sr == false) || sb == true) {
    printf("%d\n", rst.size());
    while (!rst.empty()) {
      printf("%d ", rst.front());
      rst.pop();
    }
  } else {
    printf("%d\n", bst.size());
    while (!bst.empty()) {
      printf("%d ", bst.front());
      bst.pop();
    }
  }
  return 0;
}
