#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n, m, connComps;
vector<int> Sadj[maxn], Madj[maxn], buildG[maxn], ansKey;
vector<pair<pair<int, int>, bool> > edgList;
int par[maxn];
map<pair<pair<int, int>, bool>, int> getNum;
int getpar(int a) { return (a == par[a] ? a : par[a] = getpar(par[a])); }
bool merge(int a, int b) {
  if (getpar(a) == getpar(b)) {
    return false;
  }
  par[getpar(a)] = getpar(b);
  return true;
}
void kruskal() {
  int curAdded = 0, ind = 0;
  while (curAdded < connComps - 1 && ind < edgList.size()) {
    int a = edgList[ind].first.first, b = edgList[ind].first.second;
    if (edgList[ind].second && merge(a, b)) {
      ansKey.push_back(
          getNum[pair<pair<int, int>, bool>(pair<int, int>(a, b), true)]);
      buildG[a].push_back(b);
      buildG[b].push_back(a);
      curAdded++;
    }
    ind++;
  }
  for (int i = 0; i < n; i++) {
    par[i] = i;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < buildG[i].size(); j++) {
      merge(i, buildG[i][j]);
    }
  }
  ind = 0;
  while (curAdded < (n - 1) / 2 && ind < edgList.size()) {
    int a = edgList[ind].first.first, b = edgList[ind].first.second;
    if (edgList[ind].second && merge(a, b)) {
      ansKey.push_back(
          getNum[pair<pair<int, int>, bool>(pair<int, int>(a, b), true)]);
      curAdded++;
    }
    ind++;
  }
  if (curAdded < (n - 1) / 2) {
    cout << "-1\n";
    exit(0);
  }
}
void kruskal2() {
  int curAdded = 0, ind = 0;
  while (curAdded < (n - 1) / 2 && ind < edgList.size()) {
    int a = edgList[ind].first.first, b = edgList[ind].first.second;
    if ((!edgList[ind].second) && merge(a, b)) {
      ansKey.push_back(
          getNum[pair<pair<int, int>, bool>(pair<int, int>(a, b), false)]);
      curAdded++;
    }
    ind++;
  }
  if (curAdded < (n - 1) / 2) {
    cout << "-1\n";
    exit(0);
  }
}
void dfs_vis(vector<int> graph[], int cur) {
  for (int i = 0; i < graph[cur].size(); i++) {
    int nxt = graph[cur][i];
    if (par[nxt] == 0) {
      par[nxt] = 1;
      dfs_vis(graph, nxt);
    }
  }
}
int cnt_Conn_Comp(vector<int> graph[]) {
  int conn_comp = 0;
  memset(par, 0, sizeof(par));
  for (int i = 0; i < n; i++) {
    if (par[i] == 0) {
      conn_comp++;
      par[i] = 1;
      dfs_vis(graph, i);
    }
  }
  return conn_comp;
}
int main() {
  cin >> n >> m;
  if (n % 2 == 0) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    char t;
    cin >> a >> b >> t;
    a--, b--;
    getNum[pair<pair<int, int>, bool>(pair<int, int>(a, b), t == 'S')] =
        getNum[pair<pair<int, int>, bool>(pair<int, int>(b, a), t == 'S')] =
            i + 1;
    edgList.push_back(
        pair<pair<int, int>, bool>(pair<int, int>(a, b), t == 'S'));
    if (t == 'S') {
      Sadj[a].push_back(b);
      Sadj[b].push_back(a);
    } else {
      Madj[a].push_back(b);
      Madj[b].push_back(a);
    }
  }
  connComps = cnt_Conn_Comp(Madj);
  if (connComps - 1 > (n - 1) / 2) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    par[i] = i;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < Madj[i].size(); j++) {
      merge(i, Madj[i][j]);
    }
  }
  kruskal();
  kruskal2();
  cout << ansKey.size() << '\n';
  for (int i = 0; i < ansKey.size(); i++) {
    if (i != 0) cout << ' ';
    cout << ansKey[i];
  }
  cout << '\n';
  return 0;
}
