#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 9;
int cnt, f[MAX], n, m, a, b, v[MAX], u[MAX];
char ch;
vector<pair<pair<int, int>, int> > em, es;
vector<int> ans;
int root(int v) { return f[v] < 0 ? v : f[v] = root(f[v]); }
bool merge(int a, int b) {
  if ((a = root(a)) == (b = root(b))) return false;
  if (f[a] > f[b]) swap(a, b);
  f[a] += f[b], f[b] = a;
  return true;
}
int main() {
  memset(f, -1, sizeof f);
  cin >> n >> m;
  if (n % 2 == 0) return cout << -1, 0;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> ch, a--, b--, v[i] = a, u[i] = b;
    if (ch == 'S')
      es.push_back({{a, b}, i});
    else
      em.push_back({{a, b}, i}), merge(a, b);
  }
  for (auto i : es)
    if (merge(i.first.first, i.first.second)) ans.push_back(i.second), cnt++;
  memset(f, -1, sizeof f);
  for (auto i : ans) merge(v[i], u[i]);
  for (auto i : es) {
    if (cnt == (n - 1) / 2) break;
    if (merge(i.first.first, i.first.second)) ans.push_back(i.second), cnt++;
  }
  if (cnt != (n - 1) / 2) return cout << -1, 0;
  cnt = 0;
  for (auto i : em)
    if (merge(i.first.first, i.first.second)) ans.push_back(i.second), cnt++;
  if (cnt != (n - 1) / 2) return cout << -1, 0;
  cout << n - 1 << endl;
  for (auto i : ans) cout << i + 1 << " ";
}
