#include <bits/stdc++.h>
using namespace std;
const int N = 1011, M = 101111;
int n, m;
pair<int, int> edg[M];
int vis[M], col[M], f[N];
int GetF(int a) {
  if (a == f[a]) return a;
  return f[a] = GetF(f[a]);
}
void Clear() {
  for (int i = (1); i <= (n); i++) f[i] = i;
}
char InputC() {
  char ret;
  while (!isupper(ret = getchar()))
    ;
  return ret;
}
int main() {
  cin >> n >> m;
  for (int i = (1); i <= (m); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    char c = InputC();
    edg[i] = {a, b};
    col[i] = (c == 'S');
  }
  if (n % 2 != 1) {
    printf("-1\n");
    return 0;
  }
  Clear();
  int siz;
  siz = 0;
  for (int i = (1); i <= (m); i++) {
    if (col[i]) {
      int a = GetF(edg[i].first), b = GetF(edg[i].second);
      if (a != b) {
        f[a] = b;
        siz++;
      }
    }
  }
  if (siz < (n - 1) / 2) {
    printf("-1\n");
    return 0;
  }
  for (int i = (1); i <= (m); i++) {
    if (!col[i]) {
      int a = GetF(edg[i].first), b = GetF(edg[i].second);
      if (a != b) {
        f[a] = b;
        vis[i] = 1;
        siz++;
      }
    }
  }
  if (siz < n - 1) {
    printf("-1\n");
    return 0;
  }
  Clear();
  siz = 0;
  for (int i = (1); i <= (m); i++) {
    if (vis[i]) {
      int a = GetF(edg[i].first), b = GetF(edg[i].second);
      f[a] = b;
      siz++;
    }
  }
  for (int i = (1); i <= (m); i++) {
    if (!col[i] && !vis[i]) {
      int a = GetF(edg[i].first), b = GetF(edg[i].second);
      if (a != b) {
        f[a] = b;
        vis[i] = 1;
        siz++;
        if (siz == (n - 1) / 2) break;
      }
    }
  }
  if (siz != (n - 1) / 2) {
    printf("-1\n");
    return 0;
  }
  for (int i = (1); i <= (m); i++) {
    if (col[i]) {
      int a = GetF(edg[i].first), b = GetF(edg[i].second);
      if (a != b) {
        f[a] = b;
        vis[i] = 1;
        siz++;
      }
    }
  }
  assert(siz == n - 1);
  printf("%d\n", siz);
  for (int i = (1); i <= (m); i++) {
    if (vis[i]) printf("%d ", i);
  }
  printf("\n");
  return 0;
}
