#include <bits/stdc++.h>
using namespace std;
int x[101010], y[101010], t[101010], root[1010], ans[101010];
void init(int n) {
  for (int i = 1; i <= n; i++) root[i] = i;
}
int find_root(int u) {
  if (root[u] == u) return u;
  return root[u] = find_root(root[u]);
}
void merge(int u, int v) {
  u = find_root(u);
  v = find_root(v);
  root[v] = u;
}
bool dis(int u, int v) { return find_root(u) != find_root(v); }
int main() {
  int N, M, K = 0;
  char s[3];
  cin >> N >> M;
  if (N % 2 == 0) return puts("-1");
  int m = N >> 1;
  for (int i = 1; i <= M; i++) {
    scanf("%d%d%s", x + i, y + i, s);
    if (s[0] == 'S')
      t[i] = 0;
    else
      t[i] = 1;
  }
  init(N);
  for (int i = 1; i <= M; i++) {
    if (!t[i] && dis(x[i], y[i])) merge(x[i], y[i]);
  }
  for (int i = 1; i <= M; i++) {
    if (t[i] && dis(x[i], y[i])) merge(x[i], y[i]), ans[K++] = i;
  }
  if (K > m) return puts("-1");
  init(N);
  for (int i = 0; i < K; i++) merge(x[ans[i]], y[ans[i]]);
  for (int i = 1; i <= M && K < m; i++) {
    if (t[i] && dis(x[i], y[i])) merge(x[i], y[i]), ans[K++] = i;
  }
  if (K < m) return puts("-1");
  for (int i = 1; i <= M; i++) {
    if (!t[i] && dis(x[i], y[i])) merge(x[i], y[i]), ans[K++] = i;
  }
  if (K < N - 1) return puts("-1");
  printf("%d\n", K);
  for (int i = 0; i < K; i++) printf("%d ", ans[i]);
  puts("");
  return 0;
}
