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