#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
struct ele {
  int x, t;
};
std::vector<ele> edge[100010];
int vi[100010], num, in, co[100010];
std::vector<int> ans1, ans2, p, q;
void dfs(int x, int ty) {
  vi[x] = 1;
  if (co[x] == 1)
    p.push_back(x);
  else
    q.push_back(x);
  for (int k = 0; k < edge[x].size(); k++) {
    int y = edge[x][k].x;
    if (!vi[y]) {
      if (edge[x][k].t == ty) {
        co[y] = co[x];
      } else {
        co[y] = co[x] % 2 + 1;
      }
      dfs(y, ty);
    } else {
      if (edge[x][k].t == ty) {
        if (co[x] != co[y]) {
          in = 0;
          return;
        }
      }
      if (edge[x][k].t != ty) {
        if (co[x] == co[y]) {
          in = 0;
          return;
        }
      }
    }
  }
  return;
}
int main() {
  int n, m, a, b, t, to1 = 1e9, to2 = 1e9, k, i;
  char g[10];
  scanf("%d%d", &n, &m);
  for (k = 1; k <= m; k++) {
    scanf("%d%d%s", &a, &b, g);
    if (g[0] == 'B')
      t = 0;
    else
      t = 1;
    edge[a].push_back(ele{b, t});
    edge[b].push_back(ele{a, t});
  }
  num = 0;
  in = 1;
  for (k = 1; k <= n; k++) {
    if (!vi[k]) {
      p.clear();
      q.clear();
      co[k] = 1;
      dfs(k, 0);
      num += std::min(p.size(), q.size());
      if (in == 0) break;
      if (p.size() < q.size()) {
        for (i = 0; i < p.size(); i++) {
          ans1.push_back(p[i]);
        }
      } else {
        for (i = 0; i < q.size(); i++) {
          ans1.push_back(q[i]);
        }
      }
    }
  }
  if (in) {
    to1 = num;
  }
  memset(co, 0, sizeof(co));
  memset(vi, 0, sizeof(vi));
  num = 0;
  in = 1;
  for (k = 1; k <= n; k++) {
    if (!vi[k]) {
      p.clear();
      q.clear();
      co[k] = 1;
      dfs(k, 1);
      num += std::min(p.size(), q.size());
      if (in == 0) break;
      if (p.size() < q.size()) {
        for (i = 0; i < p.size(); i++) {
          ans2.push_back(p[i]);
        }
      } else {
        for (i = 0; i < q.size(); i++) {
          ans2.push_back(q[i]);
        }
      }
    }
  }
  if (in) {
    to2 = num;
  }
  if (to1 == 1e9 && to2 == 1e9) {
    puts("-1");
  } else if (to1 < to2) {
    printf("%d\n", ans1.size());
    for (k = 0; k < ans1.size(); k++) {
      printf("%d\n", ans1[k]);
    }
  } else {
    printf("%d\n", ans2.size());
    for (k = 0; k < ans2.size(); k++) {
      printf("%d\n", ans2[k]);
    }
  }
}
