#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 200005;
constexpr int MAXINT = 1073741823;
vector<pair<pair<int, int>, int>> edges_s, edges_m;
bitset<MAXN> used_s, used_m;
int root_of[MAXN], size_of[MAXN];
int root(int v) {
  return (v == root_of[v] ? v : root_of[v] = root(root_of[v]));
}
bool merge(pair<int, int> x) {
  int u = root(x.first), v = root(x.second);
  if (u == v) return false;
  if (size_of[u] < size_of[v]) swap(u, v);
  root_of[v] = u;
  size_of[u] += size_of[v];
  size_of[v] = 0;
  return true;
}
void reset_roots(int n) {
  for (int i = 0; i < n; i++) {
    root_of[i] = i;
    size_of[i] = 1;
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, u, v, counter;
  char c;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> c;
    u--;
    v--;
    if (c == 'S')
      edges_s.emplace_back(make_pair(u, v), i);
    else
      edges_m.emplace_back(make_pair(u, v), i);
  }
  if (n % 2 == 0) {
    cout << -1;
    return 0;
  }
  reset_roots(n);
  for (pair<pair<int, int>, int> i : edges_m)
    if (merge(i.first)) used_m[i.second] = true;
  for (pair<pair<int, int>, int> i : edges_s)
    if (merge(i.first)) used_s[i.second] = true;
  counter = used_s.count();
  if (counter > (n - 1) / 2) {
    cout << -1;
    return 0;
  } else if (counter == (n - 1) / 2) {
    cout << n - 1 << '\n';
    for (int i = 0; i < m; i++)
      if (used_s[i] || used_m[i]) cout << i + 1 << ' ';
    return 0;
  }
  reset_roots(n);
  for (pair<pair<int, int>, int> i : edges_s)
    if (used_s[i.second]) merge(i.first);
  for (pair<pair<int, int>, int> i : edges_s)
    if (counter < (n - 1) / 2 && merge(i.first)) {
      used_s[i.second] = true;
      counter++;
    }
  if (counter < (n - 1) / 2) {
    cout << -1;
    return 0;
  }
  used_m.reset();
  for (pair<pair<int, int>, int> i : edges_m)
    if (merge(i.first)) used_m[i.second] = true;
  if (used_m.count() != (n - 1) / 2) {
    cout << -1;
    return 0;
  }
  cout << n - 1 << '\n';
  for (int i = 0; i < m; i++)
    if (used_s[i] || used_m[i]) cout << i + 1 << ' ';
  return 0;
}
