#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 17;
const int MAXM = 1e5 + 17;
struct EDGE {
  int u, v;
  bool st;
  EDGE(int u = 0, int v = 0, bool st = 0) : u(u), v(v), st(st) {}
} E[MAXM];
bool vis[MAXM];
int fa[MAXN];
int Find(int x) { return fa[x] == x ? x : Find(fa[x]); }
void Union(int a, int b) { fa[Find(a)] = fa[Find(b)]; }
int main() {
  int n, m;
  cin >> n >> m;
  if (!(n & 1)) {
    cout << "-1";
    return 0;
  }
  for (int i = 1; i <= m; ++i) {
    cin >> E[i].u >> E[i].v;
    char ch;
    cin >> ch;
    E[i].st = (ch == 'S');
  }
  for (int i = 1; i <= n; ++i) fa[i] = i;
  int block = n, cnt = 0;
  for (int i = 1; i <= m; ++i)
    if (E[i].st && Find(E[i].u) != Find(E[i].v)) {
      Union(E[i].u, E[i].v);
      --block;
    }
  for (int i = 1; i <= m && block > 1; ++i)
    if (!E[i].st && Find(E[i].u) != Find(E[i].v)) {
      Union(E[i].u, E[i].v);
      --block;
      ++cnt;
      vis[i] = 1;
    }
  if (block > 1 || cnt > n / 2) {
    cout << "-1";
    return 0;
  }
  for (int i = 1; i <= n; ++i) fa[i] = i;
  for (int i = 1; i <= m; ++i)
    if (vis[i]) Union(E[i].u, E[i].v);
  for (int i = 1; i <= m && cnt < n / 2; ++i)
    if (!vis[i] && !E[i].st && Find(E[i].u) != Find(E[i].v)) {
      Union(E[i].u, E[i].v);
      vis[i] = 1;
      ++cnt;
    }
  if (cnt < n / 2) {
    cout << "-1";
    return 0;
  }
  for (int i = 1; i <= m; ++i)
    if (E[i].st && Find(E[i].u) != Find(E[i].v)) {
      Union(E[i].u, E[i].v);
      vis[i] = 1;
    }
  cout << n - 1 << "\n";
  for (int i = 1; i <= m; ++i)
    if (vis[i]) cout << i << " ";
}
