#include <bits/stdc++.h>
using namespace std;
int n, m, fa[3010], S[100010], E[100010], typ[100010];
bool use[100010];
inline int getf(int x) { return x == fa[x] ? x : fa[x] = getf(fa[x]); }
char s[5];
vector<pair<int, int> > v[2];
int check(vector<pair<int, int> > &v) {
  int ret = 0;
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (auto &x : v) {
    int ti = getf(x.first), tj = getf(x.second);
    if (ti != tj) {
      fa[ti] = tj;
      ret++;
    }
  }
  return ret;
}
vector<int> ans;
int main() {
  scanf("%d%d", &n, &m);
  if (!(n & 1)) {
    puts("-1");
    return 0;
  }
  for (int i = 1, ti, tj; i <= m; i++) {
    scanf("%d%d%s", &ti, &tj, s);
    S[i] = ti;
    E[i] = tj;
    if (s[0] == 'S')
      v[0].push_back(make_pair(ti, tj)), typ[i] = 0;
    else
      v[1].push_back(make_pair(ti, tj)), typ[i] = 1;
  }
  if (check(v[0]) < (n - 1) / 2 || check(v[1]) < (n - 1) / 2) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= n; i++) fa[i] = i;
  int cnt1 = 0;
  for (int i = 1; i <= m; i++) {
    int ti = getf(S[i]), tj = getf(E[i]);
    if (ti == tj) continue;
    if (typ[i] == 0) {
      fa[ti] = tj;
    }
  }
  for (int i = 1; i <= m; i++) {
    int ti = getf(S[i]), tj = getf(E[i]);
    if (ti == tj) continue;
    if (typ[i] == 1) {
      use[i] = 1;
      fa[ti] = tj;
    }
  }
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    int ti = getf(S[i]), tj = getf(E[i]);
    if (ti == tj) continue;
    if (use[i]) fa[ti] = tj, ans.push_back(i), cnt1++;
  }
  for (int i = 1; i <= m; i++) {
    int ti = getf(S[i]), tj = getf(E[i]);
    if (ti == tj) continue;
    if (typ[i] == 1) {
      if (cnt1 < (n - 1) / 2) {
        cnt1++;
        ans.push_back(i);
        fa[ti] = tj;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    int ti = getf(S[i]), tj = getf(E[i]);
    if (ti == tj) continue;
    if (typ[i] == 0) {
      ans.push_back(i);
      fa[ti] = tj;
    }
  }
  if (ans.size() == n - 1) {
    printf("%d\n", n - 1);
    for (auto &x : ans) printf("%d ", x);
  } else
    puts("-1");
  return 0;
}
