#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3010;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int rnk[MAXN], par[MAXN];
int n, m;
vector<pair<pair<int, int>, int> > mv, sv;
int vis[MAXN];
int getpar(int a) { return par[a] == a ? a : par[a] = getpar(par[a]); }
bool merge(int a, int b) {
  int pa = getpar(a);
  int pb = getpar(b);
  if (pa == pb) {
    return false;
  }
  if (rnk[pa] < rnk[pb]) {
    par[pa] = pb;
  } else if (rnk[a] > rnk[pb]) {
    par[pb] = pa;
  } else {
    par[pa] = pb;
    rnk[pb]++;
  }
  return true;
}
void init() {
  for (int i = 0; i < n; i++) {
    rnk[i] = 1;
    par[i] = i;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    char p;
    cin >> x >> y >> p;
    x--;
    y--;
    if (p == 'S') {
      sv.push_back(pair<pair<int, int>, int>(pair<int, int>(x, y), i));
    } else if (p == 'M') {
      mv.push_back(pair<pair<int, int>, int>(pair<int, int>(x, y), i));
    }
  }
  if (n % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  init();
  int eachm = (n - 1) / 2;
  for (int i = 0; i < sv.size(); i++) {
    merge(sv[i].first.first, sv[i].first.second);
  }
  vector<pair<pair<int, int>, int> > add[2];
  for (int i = 0; i < mv.size(); i++) {
    add[merge(mv[i].first.first, mv[i].first.second)].push_back(mv[i]);
  }
  if (add[1].size() > eachm) {
    cout << "-1" << endl;
    return 0;
  }
  init();
  vector<int> res;
  for (int i = 0; i < add[1].size(); i++) {
    merge(add[1][i].first.first, add[1][i].first.second);
    res.push_back(add[1][i].second);
  }
  for (int i = 0; res.size() < eachm && i < add[0].size(); i++) {
    if (merge(add[0][i].first.first, add[0][i].first.second)) {
      res.push_back(add[0][i].second);
    }
  }
  if (res.size() != eachm) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; res.size() < 2 * eachm && i < sv.size(); i++) {
    if (merge(sv[i].first.first, sv[i].first.second)) {
      res.push_back(sv[i].second);
    }
  }
  if (res.size() != 2 * eachm) {
    cout << "-1" << endl;
    return 0;
  }
  cout << res.size() << endl;
  for (int i = 0; i < 2 * eachm; i++) {
    cout << res[i] + 1 << " ";
  }
  cout << endl;
}
