#include <bits/stdc++.h>
using namespace std;
const int max_m = 100010;
const int max_n = 1010;
int n, m;
int type[max_m];
vector<pair<int, int> > edge;
int par[max_n];
vector<int> ans;
void init() {
  for (int i = 0; i < n; i++) par[i] = i;
}
int find(int v) {
  if (par[v] == v) return v;
  return par[v] = find(par[v]);
}
void uni(int v, int u) {
  u = find(u), v = find(v);
  par[v] = u;
}
bool solve() {
  if (n % 2 == 0) return false;
  int t = (n - 1) / 2;
  init();
  for (int i = 0; i < edge.size(); i++)
    if (type[i] == 0) uni(edge[i].first, edge[i].second);
  for (int i = 0; i < edge.size(); i++) {
    int u = edge[i].first;
    int v = edge[i].second;
    if (type[i] == 1 && find(u) != find(v)) ans.push_back(i), uni(u, v);
  }
  if (ans.size() > t) return false;
  init();
  for (int i = 0; i < ans.size(); i++)
    uni(edge[ans[i]].first, edge[ans[i]].second);
  for (int i = 0; i < edge.size(); i++) {
    int u = edge[i].first;
    int v = edge[i].second;
    if (ans.size() < t && type[i] == 1 && find(u) != find(v))
      uni(u, v), ans.push_back(i);
  }
  if (ans.size() < t) return false;
  for (int i = 0; i < edge.size(); i++) {
    int u = edge[i].first;
    int v = edge[i].second;
    if (type[i] == 0 && find(u) != find(v)) uni(u, v), ans.push_back(i);
  }
  if (ans.size() != 2 * t) return false;
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    char c;
    cin >> u >> v >> c;
    u--, v--;
    edge.push_back(make_pair(u, v));
    type[i] = (c == 'S' ? 0 : 1);
  }
  if (!solve()) return cout << -1 << endl, 0;
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] + 1 << " ";
  return 0;
}
