#include <bits/stdc++.h>
using namespace std;
int N, M, u, v;
string op;
int U[100100], V[100100];
string OP[100100];
int zero[1100], one[1100];
bool isZ[100100];
bool ok[1100][1100];
int last[1100][1100];
vector<int> E[1100];
bool usd[1100];
int A[1100], pos[1100], cnt;
void DFS(int n) {
  A[cnt++] = n;
  pos[n] = cnt;
  usd[n] = true;
  for (__typeof((E[n]).begin()) it = (E[n]).begin(); it != (E[n]).end(); it++)
    if (!usd[*it]) {
      DFS(*it);
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M;
  for (long long I = 1; I <= M; I++) {
    cin >> U[I] >> V[I] >> OP[I];
    E[U[I]].push_back(V[I]);
    E[V[I]].push_back(U[I]);
  }
  DFS(1);
  for (long long I = 1; I <= M; I++) {
    u = U[I], v = V[I], op = OP[I];
    if (u == v) {
      continue;
    }
    if (pos[u] > pos[v]) swap(u, v);
    if (op == "S") {
      isZ[I] = true;
      zero[v] = I;
    } else {
      one[v] = I;
    }
  }
  ok[1][0] = true;
  for (int I = 2; I <= N; I++) {
    int n = A[I - 1];
    for (int z = 0; z <= I; z++) {
      if (z > 0 && zero[n]) {
        if (ok[I - 1][z - 1]) {
          ok[I][z] = true;
          last[I][z] = zero[n];
          assert(isZ[zero[n]]);
        }
      }
      if (!ok[I][z] && one[n]) {
        if (ok[I - 1][z]) {
          ok[I][z] = true;
          last[I][z] = one[n];
          assert(!isZ[one[n]]);
        }
      }
    }
  }
  if ((N % 2 == 0) || !ok[N][N / 2]) {
    cout << -1 << endl;
    return 0;
  }
  cout << N - 1 << endl;
  int n = N;
  int z = N / 2;
  while (last[n][z] > 0) {
    cout << last[n][z] << " ";
    if (isZ[last[n][z]]) z--;
    n = n - 1;
  }
  cout << endl;
}
