#include <bits/stdc++.h>
using namespace std;
int n, m, fa[1010], vis[100020], used[100020];
struct edge {
  int a, b, w, id;
  bool operator<(const edge& b) const { return w < b.w; }
  edge(int x = 0, int y = 0, int ok = 0, int z = 0)
      : a(x), b(y), w(ok), id(z) {}
} e[100020];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
bool unio(int x, int y) {
  int dx = find(x), dy = find(y);
  if (dx == dy) return false;
  fa[dx] = dy;
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) fa[i] = i;
  if (n % 2 == 0) return printf("-1"), 0;
  if (n == 1 || n == 0) return printf("0"), 0;
  char s[5];
  for (int a, b, i = 1; i <= m; i++) {
    scanf("%d%d%s", &a, &b, &s);
    if (s[0] == 'S')
      e[i] = edge(a, b, 1, i);
    else
      e[i] = edge(a, b, 0, i);
  }
  sort(e + 1, e + 1 + m);
  int tol = 0;
  for (int i = 1; i <= m; i++) {
    int a = e[i].a, b = e[i].b;
    if (unio(a, b) && e[i].w == 1) tol++, used[e[i].id] = 1;
  }
  if (tol * 2 + 1 > n) return printf("-1"), 0;
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    if (used[e[i].id]) unio(e[i].a, e[i].b);
  }
  for (int i = 1; i <= m; i++) {
    if (e[i].w == 1 && !used[e[i].id]) {
      if (unio(e[i].a, e[i].b)) tol++, used[e[i].id] = 1;
    }
    if (tol * 2 + 1 == n) break;
  }
  if (tol * 2 + 1 < n) return printf("-1"), 0;
  for (int i = 1; i <= m; i++) {
    if (!used[e[i].id] && e[i].w == 0) {
      if (unio(e[i].a, e[i].b)) used[e[i].id] = 1;
    }
  }
  printf("%d\n", n - 1);
  for (int i = 1; i <= m; i++) {
    if (used[i]) printf("%d ", i);
  }
  return 0;
}
