#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9;
const long long N = 3e5 + 5;
vector<long long> adj[N];
vector<long long> kq;
struct dang {
  long long vl, id, node;
};
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    pr, prn;
long long n, m, t, k, T, ans, tong, lab[N], x[N], y[N];
long long findp(long long u) { return lab[u] < 0 ? u : lab[u] = findp(lab[u]); }
void hop(long long u, long long v) {
  if (lab[u] > lab[v]) swap(u, v);
  lab[u] += lab[v];
  lab[v] = u;
}
vector<int> noen, tinh;
void sol() {
  cin >> n >> m;
  fill_n(lab, n + 2, -1);
  for (int i = 1; i <= m; i++) {
    char ch;
    cin >> x[i] >> y[i] >> ch;
    if (ch == 'S')
      noen.push_back(i);
    else {
      tinh.push_back(i);
      ++ans;
      long long u = findp(x[i]), v = findp(y[i]);
      if (u != v) hop(u, v);
    }
  }
  k = (n - 1) / 2;
  for (long long i : noen) {
    long long u = findp(x[i]), v = findp(y[i]);
    if (u != v) {
      kq.push_back(i);
      hop(u, v);
    }
  }
  fill_n(lab, n + 2, -1);
  if (kq.size() > k) {
    cout << -1;
    return;
  }
  ans = 0;
  for (long long i : kq) {
    long long u = findp(x[i]), v = findp(y[i]);
    if (u != v) {
      ++ans;
      hop(u, v);
    }
  }
  for (long long i : noen) {
    long long u = findp(x[i]), v = findp(y[i]);
    if (u != v) {
      kq.push_back(i);
      hop(u, v);
    }
    if (kq.size() == k) break;
  }
  if (kq.size() != k) {
    cout << -1;
    return;
  }
  for (long long i : tinh) {
    long long u = findp(x[i]), v = findp(y[i]);
    if (u != v) {
      kq.push_back(i);
      hop(u, v);
    }
  }
  if (kq.size() != n - 1 || kq.size() != 2 * k) {
    cout << -1;
    return;
  }
  cout << n - 1 << '\n';
  for (long long i : kq) cout << i << " ";
}
int main() {
  if (fopen("sort"
            ".in",
            "r")) {
    freopen(
        "sort"
        ".in",
        "r", stdin);
    freopen(
        "sort"
        ".out",
        "w", stdout);
  }
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  sol();
}
