#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 10 + 10, MAXE = 100 * 100 * 10 + 10;
vector<int> S, M, seq;
int par[MAXN], size[MAXN], n, m;
pair<int, int> e[MAXE];
int parent(int x) { return ((par[x] == x) ? x : (par[x] = parent(par[x]))); }
bool merge(int u, int v) {
  u = parent(u);
  v = parent(v);
  if (u == v) return false;
  if (size[u] > size[v]) swap(u, v);
  par[u] = v;
  size[v] += size[u];
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    a--;
    b--;
    e[i] = pair<int, int>(a, b);
    if (c == 'S')
      S.push_back(i);
    else
      M.push_back(i);
  }
  if (n % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int tmp = (n - 1) / 2;
  if ((int)S.size() < tmp || (int)M.size() < tmp) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i <= n; i++) {
    par[i] = i;
    size[i] = 1;
  }
  for (int i = 0; i < (int)S.size(); i++) {
    int ed = S[i];
    int u = e[ed].first, v = e[ed].second;
    ;
    merge(u, v);
  }
  for (int i = 0; i < (int)M.size(); i++) {
    int ed = M[i];
    int u = e[ed].first, v = e[ed].second;
    if (merge(u, v)) seq.push_back(ed);
  }
  if ((int)seq.size() > tmp) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i <= n; i++) {
    par[i] = i;
    size[i] = 1;
  }
  for (int i = 0; i < (int)seq.size(); i++) {
    int ed = seq[i];
    int u = e[ed].first, v = e[ed].second;
    merge(u, v);
  }
  for (int i = 0; i < (int)M.size(); i++) {
    int ed = M[i];
    int u = e[ed].first, v = e[ed].second;
    if (merge(u, v)) seq.push_back(M[i]);
    if ((int)seq.size() == tmp) break;
  }
  if ((int)seq.size() < tmp) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (int)S.size(); i++) {
    int ed = S[i];
    int u = e[ed].first, v = e[ed].second;
    if (merge(u, v)) seq.push_back(S[i]);
    if ((int)seq.size() == n - 1) break;
  }
  cout << n - 1 << " ";
  for (int i = 0; i < (int)seq.size(); i++) cout << seq[i] + 1 << " ";
  cout << endl;
  return 0;
}
