#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10, maxm = 1e5 + 10;
int fa[maxn], n, m, num, used[maxm];
struct ed {
  int x, y, id;
} e[maxm];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void Merge(int x, int y) {
  int fy = find(y);
  fa[fy] = find(x);
}
void init() {
  for (int i = 1; i <= n; i++) fa[i] = i;
}
bool jud(int x, int y) { return find(x) == find(y); }
int solve(int l) {
  init();
  for (int i = 1; i <= m; i++)
    if (used[i] && e[i].id == l)
      Merge(e[i].x, e[i].y);
    else
      used[i] = 0;
  for (int i = 1; i <= m; i++)
    if (e[i].id == l && !used[i]) {
      if (!jud(e[i].x, e[i].y)) {
        Merge(e[i].x, e[i].y);
        used[i] = 1;
        num += l;
      }
      if (num * 2 + 1 == n) break;
    }
  for (int i = 1; i <= m; i++)
    if (e[i].id != l && !used[i]) {
      if (!jud(e[i].x, e[i].y)) {
        Merge(e[i].x, e[i].y);
        used[i] = 1;
      }
    }
}
int main() {
  char a[10];
  scanf("%d%d", &n, &m);
  init();
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%s", &e[i].x, &e[i].y, a);
    e[i].id = (a[0] == 'S' ? 1 : -1);
    if (!jud(e[i].x, e[i].y)) {
      Merge(e[i].x, e[i].y);
      used[i] = 1;
      num += (e[i].id == 1);
    }
  }
  if (n % 2 == 0) {
    printf("-1");
    return 0;
  }
  if (num * 2 + 1 != n) {
    if (num * 2 + 1 > n)
      solve(-1);
    else
      solve(1);
  }
  if (num * 2 + 1 != n)
    printf("-1");
  else {
    printf("%d\n", n - 1);
    for (int i = 1; i <= m; i++)
      if (used[i]) printf("%d ", i);
  }
  return 0;
}
