#include <bits/stdc++.h>
using namespace std;
int n, m, c[100005];
bool vis[100005];
vector<pair<int, int> > adj[100005];
int col[100005];
vector<int> temp[2], ans[2];
bool flag;
void dfs(int u, int pre_col, int req_col) {
  vis[u] = true;
  col[u] = pre_col;
  temp[pre_col].push_back(u);
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i].first;
    int id = adj[u][i].second;
    int w = c[id];
    if (vis[v] == true) {
      if (w == req_col) {
        if (col[u] != col[v]) {
          flag = false;
        }
      } else {
        if (col[u] == col[v]) {
          flag = false;
        }
      }
    } else {
      if (w == req_col) {
        dfs(v, col[u], req_col);
      } else {
        dfs(v, 1 - col[u], req_col);
      }
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    string w;
    scanf("%d %d", &u, &v);
    cin >> w;
    adj[u].push_back(make_pair(v, i));
    adj[v].push_back(make_pair(u, i));
    if (w == "R")
      c[i] = 0;
    else
      c[i] = 1;
  }
  memset(col, -1, sizeof col);
  int res[2];
  res[0] = res[1] = 0;
  for (int k = 0; k <= 1; k++) {
    flag = true;
    memset(vis, false, sizeof vis);
    for (int i = 1; i <= n; i++) {
      if (vis[i] == false) {
        temp[0].clear();
        temp[1].clear();
        dfs(i, 0, k);
        if (flag == false) {
          res[k] = 1234567;
          break;
        } else {
          if (temp[0].size() < temp[1].size()) {
            for (int j = 0; j < temp[0].size(); j++) {
              ans[k].push_back(temp[0][j]);
            }
            res[k] += temp[0].size();
          } else {
            for (int j = 0; j < temp[1].size(); j++) {
              ans[k].push_back(temp[1][j]);
            }
            res[k] += temp[1].size();
          }
        }
      }
    }
    if (res[k] == 1234567) continue;
  }
  if (res[0] == 1234567 && res[1] == 1234567)
    cout << -1;
  else if (res[0] == 1234567) {
    cout << res[1] << endl;
    for (int i = 0; i < ans[1].size(); i++) {
      cout << ans[1][i] << " ";
    }
  } else if (res[1] == 1234567) {
    cout << res[0] << endl;
    for (int i = 0; i < ans[0].size(); i++) {
      cout << ans[0][i] << " ";
    }
  } else {
    if (res[0] < res[1]) {
      cout << res[0] << endl;
      for (int i = 0; i < ans[0].size(); i++) {
        cout << ans[0][i] << " ";
      }
    } else {
      cout << res[1] << endl;
      for (int i = 0; i < ans[1].size(); i++) {
        cout << ans[1][i] << " ";
      }
    }
  }
}
