#include <bits/stdc++.h>
const int maxn = 1005;
const int maxe = 100005;
struct node {
  int x, y, flag;
} edge[maxe];
int ans[maxn], fa[maxn], fb[maxn], fw[maxn], n, m;
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    char s[2];
    scanf("%d%d%s", &edge[i].x, &edge[i].y, s);
    edge[i].flag = s[0] == 'M';
  }
}
int getfa_b(int x) {
  fb[x] = fb[x] != x ? getfa_b(fb[x]) : x;
  return fb[x];
}
int getfa_w(int x) {
  fw[x] = fw[x] != x ? getfa_w(fw[x]) : x;
  return fw[x];
}
int getfa(int x) {
  fa[x] = fa[x] != x ? getfa(fa[x]) : x;
  return fa[x];
}
void work() {
  if (!(n & 1)) {
    printf("-1\n");
    return;
  }
  for (int i = 1; i <= n; i++) fa[i] = fb[i] = fw[i] = i;
  for (int i = 0; i < m; i++) {
    if (edge[i].flag) {
      int x = getfa_b(edge[i].x), y = getfa_b(edge[i].y);
      fb[y] = x;
    } else {
      int x = getfa_w(edge[i].x), y = getfa_w(edge[i].y);
      fw[y] = x;
    }
  }
  int tb = 0, tw = 0;
  for (int i = 0; i < m; i++) {
    if (edge[i].flag) {
      int x = getfa_w(edge[i].x), y = getfa_w(edge[i].y);
      if (x != y) {
        ans[++ans[0]] = i;
        fw[y] = x;
        fa[getfa(edge[i].y)] = getfa(edge[i].x);
        tb++;
      }
    } else {
      int x = getfa_b(edge[i].x), y = getfa_b(edge[i].y);
      if (x != y) {
        ans[++ans[0]] = i;
        fb[y] = x;
        fa[getfa(edge[i].y)] = getfa(edge[i].x);
        tw++;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    if (edge[i].flag) {
      if (tb == (n - 1) / 2) continue;
      int x = getfa(edge[i].x), y = getfa(edge[i].y);
      if (x == y) continue;
      ans[++ans[0]] = i;
      fa[y] = x;
      tb++;
    } else {
      if (tw == (n - 1) / 2) continue;
      int x = getfa(edge[i].x), y = getfa(edge[i].y);
      if (x == y) continue;
      ans[++ans[0]] = i;
      fa[y] = x;
      tw++;
    }
  }
  if (tb == (n - 1) / 2 && tw == (n - 1) / 2) {
    printf("%d\n", n - 1);
    for (int i = 1; i < n; i++) printf("%d ", ans[i] + 1);
  } else
    printf("-1\n");
}
int main() {
  init();
  work();
  return 0;
}
