#include <bits/stdc++.h>
using namespace std;
long long ev[100300], eu[100300], dsu1[100300], dsu2[100300];
char es[100300];
bool use[100300];
long long root(long long v, long long *dsu) {
  return dsu[v] == v ? v : dsu[v] = root(dsu[v], dsu);
}
long long merge(long long u, long long v, long long *dsu) {
  dsu[root(u, dsu)] = root(v, dsu);
}
int main() {
  long long n, m;
  scanf("%I64d %I64d", &n, &m);
  long long tree_len = n - 1, components = n, s_count = 0, m_count = 0;
  if (tree_len % 2) {
    printf("-1");
    return 0;
  }
  for (long long i = 0; i <= n; i++) dsu1[i] = dsu2[i] = i;
  for (long long i = 0; i < m; i++) {
    scanf("%I64d %I64d %c", &ev[i], &eu[i], &es[i]);
    if (es[i] == 'M' && root(ev[i], dsu1) != root(eu[i], dsu1)) {
      merge(ev[i], eu[i], dsu1);
      components--;
    }
  }
  for (long long i = 0; i < m; i++)
    if (es[i] == 'S' && root(ev[i], dsu1) != root(eu[i], dsu1)) {
      merge(ev[i], eu[i], dsu1);
      merge(ev[i], eu[i], dsu2);
      s_count++;
      use[i] = true;
    }
  for (long long i = 0; s_count < tree_len / 2 && i < m; i++)
    if (es[i] == 'S' && root(ev[i], dsu2) != root(eu[i], dsu2)) {
      merge(ev[i], eu[i], dsu2);
      s_count++;
      use[i] = true;
    }
  for (long long i = 0; m_count < tree_len / 2 && i < m; i++)
    if (es[i] == 'M' && root(ev[i], dsu2) != root(eu[i], dsu2)) {
      merge(ev[i], eu[i], dsu2);
      m_count++;
      use[i] = true;
    }
  if (s_count != tree_len / 2 || m_count != tree_len / 2) {
    printf("-1");
    return 0;
  }
  printf("%I64d\n", tree_len);
  for (long long i = 0; i < m; i++)
    if (use[i]) {
      printf("%I64d ", i + 1);
    }
  return 0;
}
