#include <bits/stdc++.h>
using namespace std;
struct DSU {
  vector<int> parent;
  DSU(int _n = 0) { parent = vector<int>(_n + 1, -1); }
  int find(int v) {
    if (parent[v] < 0) {
      return v;
    }
    return parent[v] = find(parent[v]);
  }
  bool combine(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v) {
      return false;
    }
    if (parent[u] > parent[v]) {
      swap(u, v);
    }
    parent[u] += parent[v];
    parent[v] = u;
    return true;
  }
};
const int N = 1005;
const int M = 100005;
vector<int> g[N];
int a[M], b[M], type[M];
int depth[N], parent[N];
void dfs(int v) {
  for (int i : g[v]) {
    int u = a[i] ^ b[i] ^ v;
    if (depth[u] == 0) {
      depth[u] = depth[v] + 1;
      parent[u] = i;
      dfs(u);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> A, B;
  for (int i = 1; i <= m; i++) {
    char ch;
    cin >> a[i] >> b[i] >> ch;
    if (ch == 'S') {
      type[i] = 0;
      A.push_back(i);
    } else {
      type[i] = 1;
      B.push_back(i);
    }
  }
  if (n % 2 == 0) {
    cout << -1 << '\n';
    exit(0);
  }
  DSU dsuA(n);
  DSU dsuB(n);
  vector<int> vec;
  int requiredA = (n - 1) >> 1;
  int requiredB = (n - 1) >> 1;
  for (int i : A) {
    if (dsuA.combine(a[i], b[i])) {
      vec.push_back(i);
      requiredA--;
    }
  }
  if (requiredA > 0) {
    cout << -1 << '\n';
    exit(0);
  }
  for (int i : B) {
    if (requiredB == 0) break;
    if (dsuA.combine(a[i], b[i])) {
      dsuB.combine(a[i], b[i]);
      vec.push_back(i);
      requiredB--;
    }
  }
  for (int i : B) {
    if (requiredB == 0) break;
    if (dsuB.combine(a[i], b[i])) {
      vec.push_back(i);
      requiredB--;
    }
  }
  if (requiredB > 0) {
    cout << -1 << '\n';
    exit(0);
  }
  reverse(vec.begin(), vec.end());
  cout << n - 1 << '\n';
  DSU dsu(n);
  for (int i : vec) {
    if (dsu.combine(a[i], b[i])) {
      cout << i << " ";
    }
  }
  cout << '\n';
  return 0;
}
