#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
vector<int> adgb[maxn];
vector<int> adgr[maxn];
bool mark[maxn], bb[maxn];
vector<int> v1[2];
vector<vector<int> > ans;
bool g, g1;
int s, s1;
vector<vector<int> > ans1;
void dfsr(int v, int b) {
  bb[v] = b;
  mark[v] = 1;
  for (int i = 0; i < adgb[v].size(); i++) {
    int u = adgb[v][i];
    if (mark[u] == 0)
      dfsr(u, (b + 1) % 2);
    else {
      if (bb[u] == b) g = 1;
    }
  }
  for (int i = 0; i < adgr[v].size(); i++) {
    int u = adgr[v][i];
    if (mark[u] == 0)
      dfsr(u, b);
    else {
      if (bb[u] == (b + 1) % 2) g = 1;
    }
  }
  v1[b].push_back(v);
}
void dfsb(int v, int b) {
  bb[v] = b;
  mark[v] = 1;
  for (int i = 0; i < adgr[v].size(); i++) {
    int u = adgr[v][i];
    if (mark[u] == 0)
      dfsb(u, (b + 1) % 2);
    else {
      if (bb[u] == b) g1 = 1;
    }
  }
  for (int i = 0; i < adgb[v].size(); i++) {
    int u = adgb[v][i];
    if (mark[u] == 0)
      dfsb(u, b);
    else {
      if (bb[u] == (b + 1) % 2) g1 = 1;
    }
  }
  v1[b].push_back(v);
}
int main() {
  int n, m;
  cin >> n >> m;
  char c1;
  for (int a, b, i = 0; i < m; i++) {
    cin >> a >> b >> c1;
    if (c1 == 'R') {
      adgr[a].push_back(b);
      adgr[b].push_back(a);
    }
    if (c1 == 'B') {
      adgb[a].push_back(b);
      adgb[b].push_back(a);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (mark[i] == 0) {
      v1[0].clear();
      v1[1].clear();
      dfsr(i, 0);
      if ((v1[1].size() > 0) && (v1[0].size() > 0)) {
        s += min(v1[0].size(), v1[1].size());
        if (v1[0].size() > v1[1].size())
          ans.push_back(v1[1]);
        else
          ans.push_back(v1[0]);
      }
    }
  }
  fill(mark, mark + maxn, 0);
  fill(bb, bb + maxn, 0);
  for (int i = 1; i <= n; i++) {
    if (mark[i] == 0) {
      v1[0].clear();
      v1[1].clear();
      dfsb(i, 0);
      if ((v1[1].size() > 0) && (v1[0].size() > 0)) {
        s1 += min(v1[0].size(), v1[1].size());
        if (v1[0].size() > v1[1].size())
          ans1.push_back(v1[1]);
        else
          ans1.push_back(v1[0]);
      }
    }
  }
  if ((g1 == 0) && (g == 1)) {
    cout << s1 << endl;
    for (int i = 0; i < ans1.size(); i++) {
      for (int j = 0; j < ans1[i].size(); j++) {
        cout << ans1[i][j] << endl;
      }
    }
    return 0;
  } else if ((g1 == 1) && (g == 0)) {
    cout << s << endl;
    for (int i = 0; i < ans.size(); i++) {
      for (int j = 0; j < ans[i].size(); j++) {
        cout << ans[i][j] << endl;
      }
    }
    return 0;
  } else if ((g == 0) && (g1 == 0)) {
    if (s > s1) {
      cout << s1 << endl;
      for (int i = 0; i < ans1.size(); i++) {
        for (int j = 0; j < ans1[i].size(); j++) {
          cout << ans1[i][j] << endl;
        }
      }
      return 0;
    } else {
      cout << s << endl;
      for (int i = 0; i < ans.size(); i++) {
        for (int j = 0; j < ans[i].size(); j++) {
          cout << ans[i][j] << endl;
        }
      }
      return 0;
    }
  }
  cout << -1;
  return 0;
}
