#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll inf = 2e18;
const int mod = 1e9 + 7;
const ld eps = 1e-9;
const ld pi = 3.14159265358979323846;
int n, m;
struct e {
  int u, v;
  int i;
};
vector<vector<int>> g;
vector<e> em;
vector<e> es;
vector<e> ed;
pair<int, int> dsu[3000];
void ms() {
  for (int i = 0; i < n; ++i) dsu[i] = {i, 1};
}
int fs(int v) {
  return dsu[v].first == v ? v : dsu[v].first = fs(dsu[v].first);
}
void us(int u, int v) {
  u = fs(u);
  v = fs(v);
  if (u == v) return;
  if (dsu[u].second > dsu[v].second) swap(u, v);
  dsu[u].first = v;
  dsu[v].second += dsu[u].second;
}
int usd[3000];
void dfs(int v) {
  usd[v] = true;
  for (auto i : g[v])
    if (!usd[i]) {
      us(i, v);
      dfs(i);
    }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(12);
  cout << fixed;
  cin >> n >> m;
  if (n & 1 == 0) {
    cout << -1;
    return 0;
  }
  g.resize(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    char w;
    cin >> u >> v >> w;
    --u;
    --v;
    ed.push_back({u, v, i});
    if (w == 'M') {
      em.push_back({u, v, i});
      continue;
    }
    g[u].push_back(v);
    g[v].push_back(u);
    es.push_back({u, v, i});
  }
  ms();
  for (int i = 0; i < n; ++i) dfs(i);
  vector<int> mans;
  vector<int> sans;
  for (int i = 0; i < em.size(); ++i) {
    auto [u, v, j] = em[i];
    if (fs(u) == fs(v)) continue;
    us(u, v);
    mans.push_back(j);
  }
  if (mans.size() > n / 2) {
    cout << -1;
    return 0;
  }
  ms();
  for (auto i : mans) us(ed[i].u, ed[i].v);
  for (auto i : em) {
    if (mans.size() >= n / 2) break;
    auto [u, v, j] = i;
    if (fs(u) == fs(v)) continue;
    us(u, v);
    mans.push_back(j);
  }
  if (mans.size() < n / 2) {
    cout << -1;
    return 0;
  }
  for (auto i : es) {
    if (sans.size() >= n / 2) break;
    auto [u, v, j] = i;
    if (fs(u) == fs(v)) continue;
    us(u, v);
    sans.push_back(j);
  }
  if (sans.size() < n / 2) {
    cout << -1;
    return 0;
  }
  cout << n - 1 << endl;
  for (auto i : mans) cout << i + 1 << " ";
  for (auto i : sans) cout << i + 1 << " ";
  cout << endl;
  return 0;
}
