#include <bits/stdc++.h>
using namespace std;
static char s[2];
struct Edge {
  int u, v;
  bool T;
  void Read() {
    scanf("%d%d%s", &u, &v, s);
    T = *s == 'S';
  }
} R[100005];
int p[1003], n, m;
bool usd[100005];
int getf(int x) {
  if (p[x] == x) return x;
  return p[x] = getf(p[x]);
}
int Ret() {
  puts("-1");
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  if (~n & 1) return Ret();
  for (int i = 1; i <= m; i++) R[i].Read();
  for (int i = 1; i <= n; i++) p[i] = i;
  int B = n, E = 0;
  for (int i = 1; i <= m; i++)
    if (R[i].T) {
      int x = getf(R[i].u), y = getf(R[i].v);
      if (x == y) continue;
      p[x] = y, B--;
    }
  for (int i = 1; i <= m && B > 1; i++)
    if (!R[i].T) {
      int x = getf(R[i].u), y = getf(R[i].v);
      if (x == y) continue;
      p[x] = y, usd[i] = true;
      B--, E++;
    }
  if (B > 1 || E > n / 2) return Ret();
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= m; i++)
    if (usd[i]) {
      int x = getf(R[i].u), y = getf(R[i].v);
      p[x] = y;
    }
  for (int i = 1; i <= m && E < n / 2; i++)
    if (!usd[i] && !R[i].T) {
      int x = getf(R[i].u), y = getf(R[i].v);
      if (x == y) continue;
      p[x] = y, usd[i] = true;
      E++;
    }
  if (E < n / 2) return Ret();
  E = 0;
  for (int i = 1; i <= m; i++)
    if (R[i].T) {
      int x = getf(R[i].u), y = getf(R[i].v);
      if (x == y) continue;
      p[x] = y, usd[i] = true;
    }
  printf("%d\n", n - 1);
  for (int i = 1; i <= m; i++)
    if (usd[i]) printf("%d ", i);
  return 0;
}
