#include <bits/stdc++.h>
using namespace std;
struct w {
  int a, b, i;
} wt;
int n, m, ta, tb;
int par[1005];
vector<w> e[2];
char y;
int cnt;
vector<int> ans;
vector<int> aa;
vector<bool> used;
int find(int x) {
  if (par[x] == x) return x;
  return par[x] = find(par[x]);
}
int main() {
  scanf("%d", &n);
  if (!(n & 1)) {
    printf("-1\n");
    return 0;
  }
  scanf("%d", &m);
  for (int a = 1; a <= m; a++) {
    scanf("%d", &wt.a);
    scanf("%d", &wt.b);
    scanf(" %c", &y);
    wt.a--;
    wt.b--;
    wt.i = a;
    e[y == 'S'].push_back(wt);
  }
  for (int a = 0; a < n; a++) par[a] = a;
  for (int a = 0; a < e[0].size(); a++)
    if (find(e[0][a].a) != find(e[0][a].b)) {
      par[find(e[0][a].a)] = e[0][a].b;
      cnt++;
    }
  for (int a = 0; a < e[1].size(); a++) {
    if (find(e[1][a].a) != find(e[1][a].b)) {
      par[find(e[1][a].a)] = e[1][a].b;
      aa.push_back(a);
      ans.push_back(e[1][a].i);
      used.push_back(1);
    } else
      used.push_back(0);
  }
  if (ans.size() + cnt != n - 1) {
    printf("-1\n");
    return 0;
  }
  if (ans.size() > n / 2) {
    printf("-1\n");
    return 0;
  }
  for (int a = 0; a < n; a++) par[a] = a;
  for (int a = 0; a < aa.size(); a++) par[find(e[1][aa[a]].a)] = e[1][aa[a]].b;
  for (int a = 0; ans.size() != n / 2; a++) {
    if (a == e[1].size()) {
      printf("-1\n");
      return 0;
    }
    if (!used[a])
      if (find(e[1][a].a) != find(e[1][a].b)) {
        par[find(e[1][a].a)] = e[1][a].b;
        ans.push_back(e[1][a].i);
      }
  }
  for (int a = 0; a < e[0].size(); a++)
    if (find(e[0][a].a) != find(e[0][a].b)) {
      par[find(e[0][a].a)] = e[0][a].b;
      ans.push_back(e[0][a].i);
      if (ans.size() == n - 1) break;
    }
  printf("%d\n", ans.size());
  for (int a = 0; a < ans.size(); a++) {
    if (a != 0) printf(" ");
    printf("%d", ans[a]);
  }
  printf("\n");
  return 0;
}
