#include <bits/stdc++.h>
using namespace std;
const int N = 1100;
int n, m, nrcomp, comp[N];
vector<int> vm[N], ve[N];
bool ver[N];
void df1(int nod) {
  ver[nod] = 1;
  vector<int>::iterator it;
  for (it = vm[nod].begin(); it != vm[nod].end(); ++it)
    if (!ver[*it]) df1(*it);
  for (it = ve[nod].begin(); it != ve[nod].end(); ++it)
    if (!ver[*it]) df1(*it);
}
void df2(int nod) {
  ver[nod] = 1;
  comp[nod] = nrcomp;
  for (vector<int>::iterator it = vm[nod].begin(); it != vm[nod].end(); ++it)
    if (!ver[*it]) df2(*it);
}
const int M = 110000;
int a[M], b[M], p[N], pn[N], nrm;
char t[M];
vector<int> rez;
int rad(int p[], int nod) {
  if (!p[nod]) return nod;
  return (p[nod] = rad(p, p[nod]));
}
int main() {
  int i;
  cin >> n >> m;
  if ((n & 1) == 0) {
    cout << -1;
    return 0;
  }
  if (n == 1) {
    cout << 0;
    return 0;
  }
  for (i = 1; i <= m; ++i) {
    cin >> a[i] >> b[i] >> t[i];
    if (t[i] == 'S') {
      vm[a[i]].push_back(b[i]);
      vm[b[i]].push_back(a[i]);
    } else {
      ve[a[i]].push_back(b[i]);
      ve[b[i]].push_back(a[i]);
    }
  }
  int nrc = 0;
  for (i = 1; i <= n; ++i)
    if (!ver[i]) {
      df1(i);
      ++nrc;
    }
  if (nrc != 1) {
    cout << "-1";
    return 0;
  }
  memset(ver, 0, sizeof(ver));
  for (i = 1; i <= n; ++i)
    if (!ver[i]) {
      ++nrcomp;
      df2(i);
    }
  if (nrcomp - 1 > n / 2) {
    cout << "-1";
    return 0;
  }
  for (i = 1; i <= m; ++i)
    if (t[i] == 'M' && comp[a[i]] != comp[b[i]]) {
      int r1 = rad(p, comp[a[i]]), r2 = rad(p, comp[b[i]]);
      if (r1 != r2) {
        rez.push_back(i);
        ++nrm;
        p[r1] = r2;
      }
    }
  for (i = 1; i <= m && nrm < n / 2; ++i)
    if (t[i] == 'M' && comp[a[i]] == comp[b[i]]) {
      int r1 = rad(pn, a[i]), r2 = rad(pn, b[i]);
      if (r1 != r2) {
        rez.push_back(i);
        ++nrm;
        pn[r1] = r2;
      }
    }
  if (nrm != n / 2) {
    cout << -1;
    return 0;
  }
  nrm = 0;
  for (i = 1; i <= m && nrm < n / 2; ++i)
    if (t[i] != 'M') {
      int r1 = rad(pn, a[i]), r2 = rad(pn, b[i]);
      if (r1 != r2) {
        rez.push_back(i);
        ++nrm;
        pn[r1] = r2;
      }
    }
  if (nrm != n / 2) {
    cout << "-1";
    return 0;
  }
  cout << rez.size() << "\n";
  for (i = 0; i < rez.size(); ++i) cout << rez[i] << " ";
  return 0;
}
