#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v, w, id;
  edge(){};
  edge(int u1, int v1, int w1, int id1) : u(u1), v(v1), w(w1), id(id1){};
  bool operator<(const edge &a) const { return w < a.w; }
} e[100010];
int fa[1010];
bool vis[100010];
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }
bool Union(int u, int v) {
  u = Find(u), v = Find(v);
  if (u == v) return 0;
  fa[u] = v;
  return 1;
}
int main() {
  int n, m, k;
  char s[5];
  scanf("%d%d", &n, &m);
  if (n % 2 == 0) {
    printf("-1\n");
    return 0;
  }
  if (n == 1) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%s", &e[i].u, &e[i].v, s);
    e[i].w = s[0] == 'S';
    e[i].id = i;
  }
  sort(e + 1, e + 1 + m);
  int tot = 0;
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++)
    if (Union(e[i].u, e[i].v) && e[i].w) tot++, vis[e[i].id] = 1;
  if (tot > (n - 1) / 2) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++)
    if (vis[e[i].id]) Union(e[i].u, e[i].v);
  for (int i = 1; i <= m; i++)
    if (!vis[e[i].id] && e[i].w == 1) {
      if (tot == (n - 1) / 2) break;
      if (Union(e[i].u, e[i].v)) tot++, vis[e[i].id] = 1;
    }
  if (tot < (n - 1) / 2) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i <= m; i++)
    if (!vis[e[i].id] && e[i].w == 0) {
      if (Union(e[i].u, e[i].v)) vis[e[i].id] = 1;
    }
  printf("%d\n", n - 1);
  for (int i = 1; i <= m; i++)
    if (vis[i]) printf("%d ", i);
}
