#include <bits/stdc++.h>
using namespace std;
long long n, m, u, v, src, cnt, tmp, Min, ans1, ans2;
long long R[100005], B[100005], Cnt[100005], col[100005], col1[100005];
char ch;
vector<vector<long long> > gr;
vector<vector<long long> > gb;
vector<vector<long long> > g;
vector<long long> a1;
vector<long long> a2;
vector<long long> arr;
vector<long long> brr;
vector<bool> vis;
vector<pair<long long, long long> > blue;
vector<pair<long long, long long> > red;
void printR(long long i) {
  cout << i << " ";
  long long sz = gr[i].size();
  vis[i] = 1;
  for (long long v = (long long)(0); v <= (long long)(sz - 1); v++)
    if (!vis[gr[i][v]]) printR(gr[i][v]);
}
void printB(long long i) {
  cout << i << " ";
  long long sz = gb[i].size();
  vis[i] = 1;
  for (long long v = (long long)(0); v <= (long long)(sz - 1); v++)
    if (!vis[gb[i][v]]) printB(gb[i][v]);
}
void dfsR(long long i) {
  long long sz = gr[i].size();
  vis[i] = 1;
  R[i] = src;
  cnt++;
  for (long long v = (long long)(0); v <= (long long)(sz - 1); v++)
    if (!vis[gr[i][v]]) dfsR(gr[i][v]);
}
void dfsB(long long i) {
  long long sz = gb[i].size();
  vis[i] = 1;
  B[i] = src;
  cnt++;
  for (long long v = (long long)(0); v <= (long long)(sz - 1); v++)
    if (!vis[gb[i][v]]) dfsB(gb[i][v]);
}
bool dfs(long long u, long long flag) {
  bool val = 1;
  col[u] = flag;
  if (flag) {
    arr.push_back(u);
    tmp += Cnt[u];
  }
  long long sz = g[u].size();
  for (long long i = (long long)(0); i <= (long long)(sz - 1); i++) {
    v = g[u][i];
    if (col[v] == -1)
      val = val && dfs(v, 1 - flag);
    else if (col[v] == flag)
      return 0;
    if (val == 0) break;
  }
  return val;
}
bool dfs1(long long u, long long flag) {
  bool val = 1;
  col1[u] = flag;
  if (flag) {
    brr.push_back(u);
    tmp += Cnt[u];
  }
  long long sz = g[u].size();
  for (long long i = (long long)(0); i <= (long long)(sz - 1); i++) {
    v = g[u][i];
    if (col1[v] == -1)
      val = val && dfs1(v, 1 - flag);
    else if (col1[v] == flag)
      return 0;
    if (val == 0) break;
  }
  return val;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  gr = vector<vector<long long> >(n + 1);
  gb = vector<vector<long long> >(n + 1);
  vis = vector<bool>(n + 1, 0);
  for (long long i = (long long)(1); i <= (long long)(m); i++) {
    cin >> u >> v >> ch;
    if (ch == 'R') {
      gr[u].push_back(v);
      gr[v].push_back(u);
      red.push_back({u, v});
    } else {
      gb[u].push_back(v);
      gb[v].push_back(u);
      blue.push_back({u, v});
    }
  }
  for (long long i = (long long)(1); i <= (long long)(n); i++) {
    if (!vis[i]) {
      src = i;
      cnt = 0;
      dfsR(i);
      Cnt[src] = cnt;
    }
  }
  g = vector<vector<long long> >(n + 1);
  long long sz = blue.size();
  bool flag = 1;
  for (long long i = (long long)(0); i <= (long long)(sz - 1); i++) {
    u = blue[i].first;
    v = blue[i].second;
    if (R[u] == R[v]) {
      flag = 0;
      break;
    }
    g[R[u]].push_back(R[v]);
    g[R[v]].push_back(R[u]);
  }
  memset(col, -1, sizeof(col));
  memset(col1, -1, sizeof(col1));
  if (flag) {
    for (long long i = (long long)(1); i <= (long long)(n); i++) {
      tmp = 0;
      Min = LLONG_MAX;
      u = R[i];
      if (col[u] == -1) {
        arr.clear();
        brr.clear();
        flag = dfs(u, 1);
        if (!flag) break;
        Min = min(Min, tmp);
        tmp = 0;
        dfs1(u, 0);
        if (tmp < Min) {
          Min = tmp;
          long long siz = brr.size();
          for (long long i = (long long)(0); i <= (long long)(siz - 1); i++)
            a1.push_back(brr[i]);
        } else {
          long long siz = arr.size();
          for (long long i = (long long)(0); i <= (long long)(siz - 1); i++)
            a1.push_back(arr[i]);
        }
        ans1 += Min;
      }
    }
  }
  if (!flag) ans1 = LLONG_MAX;
  vis = vector<bool>(n + 1, 0);
  for (long long i = (long long)(1); i <= (long long)(n); i++) {
    if (!vis[i]) {
      src = i;
      cnt = 0;
      dfsB(i);
      Cnt[src] = cnt;
    }
  }
  g = vector<vector<long long> >(n + 1);
  sz = red.size();
  flag = 1;
  for (long long i = (long long)(0); i <= (long long)(sz - 1); i++) {
    u = red[i].first;
    v = red[i].second;
    if (B[u] == B[v]) {
      flag = 0;
      break;
    }
    g[B[u]].push_back(B[v]);
    g[B[v]].push_back(B[u]);
  }
  memset(col, -1, sizeof(col));
  memset(col1, -1, sizeof(col1));
  if (flag) {
    for (long long i = (long long)(1); i <= (long long)(n); i++) {
      tmp = 0;
      Min = LLONG_MAX;
      u = B[i];
      if (col[u] == -1) {
        arr.clear();
        brr.clear();
        flag = dfs(u, 1);
        if (!flag) break;
        Min = min(Min, tmp);
        tmp = 0;
        dfs1(u, 0);
        if (tmp < Min) {
          Min = tmp;
          long long siz = brr.size();
          for (long long i = (long long)(0); i <= (long long)(siz - 1); i++)
            a2.push_back(brr[i]);
        } else {
          long long siz = arr.size();
          for (long long i = (long long)(0); i <= (long long)(siz - 1); i++)
            a2.push_back(arr[i]);
        }
        ans2 += Min;
      }
    }
  }
  if (!flag) ans2 = LLONG_MAX;
  if (ans1 == LLONG_MAX && ans2 == LLONG_MAX) {
    cout << "-1" << endl;
    return 0;
  }
  vis = vector<bool>(n + 1, 0);
  if (ans1 < ans2) {
    cout << ans1 << endl;
    long long siz = a1.size();
    for (long long i = (long long)(0); i <= (long long)(siz - 1); i++)
      printR(a1[i]);
  } else {
    cout << ans2 << endl;
    long long siz = a2.size();
    for (long long i = (long long)(0); i <= (long long)(siz - 1); i++)
      printB(a2[i]);
  }
  return 0;
}
