#include <bits/stdc++.h>
using namespace std;
const long long mx = 100009;
int from[mx], to[mx], type[mx], par[mx];
int n, m;
vector<int> ans[2];
void reset() {
  for (int i = 1; i <= n; i++) par[i] = i;
}
int findp(int a) {
  if (par[a] == a) return a;
  return par[a] = findp(par[a]);
}
bool join(int a, int b) {
  a = findp(a);
  b = findp(b);
  if (a != b) {
    par[a] = b;
    return 1;
  }
  return 0;
}
void comp(int k) {
  reset();
  for (int i = 0; i < m; i++) {
    if (type[i] == k) continue;
    join(from[i], to[i]);
  }
  for (int i = 0; i < m; i++) {
    if (type[i] == k and join(from[i], to[i])) ans[k].push_back(i);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    char c;
    cin >> from[i] >> to[i] >> c;
    if (c == 'S') type[i] = 1;
  }
  if (n % 2 == 0) {
    cout << -1 << '\n';
    return 0;
  }
  int each = (n - 1) / 2;
  comp(0);
  comp(1);
  if (max((int)ans[0].size(), (int)ans[1].size()) > each) {
    cout << -1 << '\n';
    return 0;
  }
  reset();
  for (int i = 0; i < 2; i++)
    for (auto x : ans[i]) {
      join(from[x], to[x]);
    }
  for (int i = 0; i < m; i++) {
    if ((int)ans[type[i]].size() < each and join(from[i], to[i]))
      ans[type[i]].push_back(i);
  }
  if ((int)ans[0].size() + (int)ans[1].size() != each * 2)
    cout << -1 << '\n';
  else {
    cout << n - 1 << '\n';
    for (int i = 0; i < 2; i++)
      for (auto x : ans[i]) cout << x + 1 << ' ';
    cout << '\n';
  }
}
