#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, N = 1e3 + 10;
int tp[maxn], x[maxn], y[maxn];
vector<int> edge;
char ch[2];
int rt[N], V, E, i, k;
int root(int u) {
  if (rt[u] < 0)
    return u;
  else
    return rt[u] = root(rt[u]);
}
void init(int _V) {
  for (i = 1; i <= _V; i++) rt[i] = -1;
}
void merge(int u, int v) {
  u = root(u);
  v = root(v);
  if (rt[u] < rt[v]) {
    rt[u] += rt[v];
    rt[v] = u;
  } else {
    rt[v] += rt[u];
    rt[u] = v;
  }
}
void Read() {
  scanf("%d%d", &V, &E);
  for (i = 1; i <= E; i++) {
    scanf("%d%d%s", x + i, y + i, ch);
    tp[i] = (ch[0] == 'S') ? 1 : 0;
  }
}
void runs() {
  if (V % 2 != 1) puts("-1"), exit(0);
  k = V >> 1;
  init(V);
  for (i = 1; i <= E; i++)
    if (!tp[i] and root(x[i]) != root(y[i])) {
      merge(x[i], y[i]);
    }
  for (i = 1; i <= E; i++)
    if (tp[i] and root(x[i]) != root(y[i])) {
      edge.push_back(i);
      merge(x[i], y[i]);
    }
  if (((int)((edge).size())) > k) puts("-1"), exit(0);
  init(V);
  for (i = 0; i < ((int)((edge).size())); i++) merge(x[edge[i]], y[edge[i]]);
  for (i = 1; i <= E; i++)
    if (((int)((edge).size())) < k and tp[i] and root(x[i]) != root(y[i])) {
      edge.push_back(i);
      merge(x[i], y[i]);
    }
  if (((int)((edge).size())) < k) puts("-1"), exit(0);
  for (i = 1; i <= E; i++)
    if (!tp[i] and root(x[i]) != root(y[i])) {
      edge.push_back(i);
      merge(x[i], y[i]);
    }
  if (((int)((edge).size())) < 2 * k) puts("-1"), exit(0);
  printf("%d\n", V - 1);
  for (i = 0; i < ((int)((edge).size())); i++) printf("%d ", edge[i]);
  puts("");
}
int main() {
  Read();
  runs();
}
