#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int par[3][N], sz[3][N], u[N], v[N];
char ch[N];
vector<int> ans;
int findpar(int f, int v) {
  if (par[f][v] == v) return v;
  return (par[f][v] = findpar(f, par[f][v]));
}
bool merge(int f, int u, int v) {
  u = findpar(f, u), v = findpar(f, v);
  if (u == v) return 0;
  if (sz[u] > sz[v]) swap(u, v);
  sz[f][v] += sz[f][u];
  par[f][u] = v;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  int sz1 = n, num = n / 2;
  if (n % 2 == 0) return cout << -1 << endl, 0;
  for (int i = 0; i < n; i++) {
    par[0][i] = par[1][i] = i;
    sz[0][i] = sz[1][i] = 1;
  }
  for (int i = 0; i < m; i++) {
    cin >> u[i] >> v[i] >> ch[i];
    u[i]--, v[i]--;
    if (ch[i] == 'M' && merge(0, u[i], v[i])) sz1--;
  }
  for (int i = 0; i < m && sz1 > 1 && num; i++)
    if (ch[i] == 'S' && merge(0, u[i], v[i])) {
      sz1--;
      num--;
      ans.push_back(i);
      merge(1, u[i], v[i]);
    }
  for (int i = 0; i < m && num; i++) {
    if (ch[i] == 'S' && merge(1, u[i], v[i])) {
      num--;
      ans.push_back(i);
    }
  }
  if (sz1 > 1 || num) return cout << -1 << endl, 0;
  num = n / 2;
  for (int i = 0; i < m && num; i++)
    if (ch[i] == 'M' && merge(1, u[i], v[i])) {
      num--;
      ans.push_back(i);
    }
  if (ans.size() == n - 1) {
    cout << ans.size() << endl;
    for (int u : ans) cout << u + 1 << " ";
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
