#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + (s - '0');
    s = getchar();
  }
  return x * f;
}
const int jzm = 1000000007;
int n, m, i, j, s, o, k;
struct it {
  int u, v, id;
  it() { u = v = id = 0; }
  it(int U, int V, int I) { u = U, v = V, id = I; }
} e1[100005], e2[100005];
int fa1[1005], fa2[1005];
int findf1(int x) { return x == fa1[x] ? x : (fa1[x] = findf1(fa1[x])); }
void unionSet1(int a, int b) {
  int u = findf1(a), v = findf1(b);
  if (u != v) fa1[u] = v;
}
int findf2(int x) { return x == fa2[x] ? x : (fa2[x] = findf2(fa2[x])); }
void unionSet2(int a, int b) {
  int u = findf2(a), v = findf2(b);
  if (u != v) fa2[u] = v;
}
int pr[1005], cnt;
int main() {
  n = read();
  m = read();
  int c1 = 0, c2 = 0;
  for (int i = 1; i <= n; i++) fa1[i] = fa2[i] = i;
  for (int i = 1; i <= m; i++) {
    s = read();
    o = read();
    char ss;
    cin >> ss;
    if (ss == 'S') {
      e1[++c1] = it(s, o, i);
    } else
      e2[++c2] = it(s, o, i);
  }
  int ed = 0;
  for (int i = 1; i <= c1; i++) {
    if (findf1(e1[i].u) ^ findf1(e1[i].v)) {
      unionSet1(e1[i].u, e1[i].v);
      ed++;
    }
  }
  if (ed * 2 < n - 1 || n % 2 == 0) {
    printf("-1");
    return 0;
  }
  int bl = 0;
  for (int i = 1; i <= c2; i++) {
    if (findf1(e2[i].u) ^ findf1(e2[i].v)) {
      unionSet1(e2[i].u, e2[i].v);
      unionSet2(e2[i].u, e2[i].v);
      ed++;
      bl++;
      pr[++cnt] = e2[i].id;
    }
  }
  if (ed < n - 1) {
    printf("-1");
    return 0;
  }
  for (int i = 1; i <= c2 && bl * 2 < n - 1; i++) {
    if (findf2(e2[i].u) ^ findf2(e2[i].v)) {
      unionSet2(e2[i].u, e2[i].v);
      bl++;
      pr[++cnt] = e2[i].id;
    }
  }
  if (bl * 2 != n - 1) {
    printf("-1");
    return 0;
  }
  for (int i = 1; i <= c1; i++) {
    if (findf2(e1[i].u) ^ findf2(e1[i].v)) {
      unionSet2(e1[i].u, e1[i].v);
      pr[++cnt] = e1[i].id;
    }
  }
  printf("%d\n", n - 1);
  for (int i = 1; i <= cnt; i++) {
    printf("%d ", pr[i]);
  }
  putchar('\n');
  return 0;
}
