#include <bits/stdc++.h>
using namespace std;
int n, m;
const double oo = 2e5;
const int Maxn = 1e3 + 9;
const int Maxm = 1e5 + 9;
vector<pair<double, int> > edges;
pair<int, int> edge[Maxm];
int has[Maxm];
int par[Maxn];
vector<int> mst;
int find(int v) {
  if (par[v] != v) return par[v] = find(par[v]);
  return v;
}
bool unite(int u, int v) {
  u = find(u), v = find(v);
  if (u == v) return 0;
  par[u] = v;
  return 1;
}
int check(double x) {
  edges.clear(), mst.clear();
  for (int i = 0; i < n; i++) par[i] = i;
  for (int i = 0; i < m; i++) {
    if (edge[i].first != edge[i].second)
      edges.push_back(make_pair(has[i] * x + 100 + (double)10 / i, i));
  }
  sort(edges.begin(), edges.end());
  int res = 0;
  for (int i = 0; i < edges.size(); i++) {
    int id = edges[i].second;
    int u = edge[id].first, v = edge[id].second;
    if (unite(u, v)) res += has[id], mst.push_back(id);
  }
  return res;
}
double bs(double l, double r) {
  for (int i = 0; i < 50; i++) {
    double mid = (l + r) / 2;
    if (check(mid) == n / 2) {
      l = mid;
      break;
    }
    if (check(mid) >= n / 2)
      l = mid;
    else
      r = mid;
  }
  return l;
}
int main() {
  scanf("%d%d", &n, &m);
  if (n % 2 == 0) {
    puts("-1");
    return 0;
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    char st;
    scanf("%d %d %c", &u, &v, &st);
    if (st == 'S') has[i] = 1;
    edge[i] = make_pair(--u, --v);
  }
  double ans = bs(-oo, oo);
  if (mst.size() != n - 1 || check(ans) != n / 2) {
    puts("-1");
    return 0;
  }
  printf("%d\n", n - 1);
  for (int i = 0; i < mst.size(); i++) printf("%d ", mst[i] + 1);
  puts("");
  return 0;
}
