#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
struct edge {
  int u, v, id;
  edge(int a = 0, int b = 0, int c = 0) { u = a, v = b, id = c; }
};
vector<edge> S, M, E;
struct dsu {
  int par[N];
  vector<edge> ed;
  dsu() { memset(par, -1, sizeof par); }
  int get_par(int u) { return ~par[u] ? par[u] = get_par(par[u]) : u; }
  bool merge(edge e) {
    if (get_par(e.u) == get_par(e.v)) return false;
    par[get_par(e.u)] = get_par(e.v), ed.push_back(e);
    return true;
  }
  int size() { return ed.size(); }
} A, B, C;
int n, m;
void notValid() { cout << "-1\n", exit(0); }
void readInput() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    char c;
    int u, v;
    cin >> u >> v >> c;
    u--, v--;
    if (c == 'S')
      S.push_back(edge(u, v, i));
    else
      M.push_back(edge(u, v, i));
  }
}
void solve() {
  for (auto e : S) C.merge(e);
  if (n & 1 ^ 1 || C.size() < n >> 1) notValid();
  for (auto e : M)
    if (C.merge(e)) A.merge(e);
  if (C.size() != n - 1) notValid();
  for (auto e : M)
    if (A.size() < n >> 1) A.merge(e);
  if (A.size() != n >> 1) notValid();
  E = A.ed;
  for (auto e : S)
    if (A.merge(e)) B.merge(e);
  E.insert(E.end(), B.ed.begin(), B.ed.end());
}
void writeOutput() {
  cout << n - 1 << endl;
  for (auto e : E) cout << e.id + 1 << ' ';
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  readInput(), solve(), writeOutput();
  return 0;
}
