#include <bits/stdc++.h>
using namespace std;
int n, m, col[100005], ans, ans2, tmp, cnt;
int a[100005], b[100005], c[100005], tog[100005], tog2[100005];
vector<int> v[100005], last;
bool vis[100005];
void dfs(int id, int cc) {
  vis[id] = true;
  last.push_back(id);
  col[id] = cc;
  if (cc) tmp++;
  for (int i = (0); i <= ((int)v[id].size() - 1); i++) {
    int j = v[id][i];
    int tar = a[j] + b[j] - id;
    if (vis[tar]) {
      if (col[id] ^ col[tar] != c[j]) tmp = 999999;
    } else
      dfs(tar, c[j] ^ cc);
  }
  return;
}
void run() {
  ans = 0;
  for (int i = (1); i <= (n); i++)
    if (!vis[i]) {
      tmp = 0;
      dfs(i, 0);
      cnt = last.size();
      if (tmp < 999999 && tmp + tmp > cnt) {
        for (int i = (0); i <= ((int)last.size() - 1); i++)
          col[last[i]] = 1 - col[last[i]];
        tmp = cnt - tmp;
      }
      last.clear();
      ans += tmp;
      ans = min(ans, 999999);
    }
  for (int i = (1); i <= (n); i++) tog[i] = col[i];
  return;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (1); i <= (m); i++) {
    char cc;
    scanf("%d %d %c", &a[i], &b[i], &cc);
    if (cc == 'B')
      c[i] = 1;
    else
      c[i] = 0;
    v[a[i]].push_back(i);
    v[b[i]].push_back(i);
  }
  run();
  ans2 = ans;
  for (int i = (1); i <= (n); i++) tog2[i] = tog[i];
  memset(vis, 0, sizeof(vis));
  memset(col, 0, sizeof(col));
  memset(tog, 0, sizeof(tog));
  for (int i = (1); i <= (m); i++) c[i] = 1 - c[i];
  run();
  if (ans2 >= 999999 && ans >= 999999)
    printf("-1\n");
  else if (ans < ans2) {
    printf("%d\n", ans);
    for (int i = (1); i <= (n); i++)
      if (tog[i]) printf("%d\n", i);
  } else {
    printf("%d\n", ans2);
    for (int i = (1); i <= (n); i++)
      if (tog2[i]) printf("%d\n", i);
  }
  return 0;
}
