#include <bits/stdc++.h>
using namespace std;
int par[1100], sz[1100];
int n, m;
vector<pair<pair<int, int>, int> > v1, v2, vag1, vag2;
int dsu_find(int x) {
  if (x == par[x]) return x;
  int l = dsu_find(par[x]);
  par[x] = l;
  return l;
}
bool dsu_unite(int x, int y) {
  int a = dsu_find(x), b = dsu_find(y);
  if (a == b) return 0;
  if (sz[a] > sz[b]) {
    sz[a] += sz[b];
    par[b] = a;
  } else {
    sz[b] += sz[a];
    par[a] = b;
  }
  return 1;
}
void mem() {
  for (int i = 1; i <= n; i++) {
    sz[i] = 1;
    par[i] = i;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  if (n % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    char s[3];
    scanf("%d%d", &a, &b);
    scanf("%s", s);
    if (s[0] == 'S') {
      v1.push_back(make_pair(make_pair(a, b), i));
    } else {
      v2.push_back(make_pair(make_pair(a, b), i));
    }
  }
  mem();
  for (int i = 0; i < v2.size(); i++) {
    dsu_unite(v2[i].first.first, v2[i].first.second);
  }
  for (int i = 0; i < v1.size(); i++) {
    if (dsu_unite(v1[i].first.first, v1[i].first.second)) {
      vag1.push_back(v1[i]);
    }
  }
  mem();
  for (int i = 0; i < v1.size(); i++) {
    dsu_unite(v1[i].first.first, v1[i].first.second);
  }
  for (int i = 0; i < v2.size(); i++) {
    if (dsu_unite(v2[i].first.first, v2[i].first.second)) {
      vag2.push_back(v2[i]);
    }
  }
  if (vag1.size() > (n - 1) / 2 || vag2.size() > (n - 1) / 2) {
    cout << "-1" << endl;
    return 0;
  }
  mem();
  for (int i = 0; i < vag1.size(); i++) {
    dsu_unite(vag1[i].first.first, vag1[i].first.second);
  }
  for (int i = 0; i < vag2.size(); i++) {
    dsu_unite(vag2[i].first.first, vag2[i].first.second);
  }
  for (int i = 0; i < v1.size(); i++) {
    if (vag1.size() == (n - 1) / 2) break;
    if (dsu_unite(v1[i].first.first, v1[i].first.second)) {
      vag1.push_back(v1[i]);
    }
  }
  for (int i = 0; i < v2.size(); i++) {
    if (vag2.size() == (n - 1) / 2) break;
    if (dsu_unite(v2[i].first.first, v2[i].first.second)) {
      vag2.push_back(v2[i]);
    }
  }
  if (!(vag1.size() == vag2.size() && vag1.size() + vag2.size() == n - 1)) {
    cout << "-1" << endl;
    return 0;
  }
  cout << n - 1 << endl;
  for (int i = 0; i < vag1.size(); i++) cout << vag1[i].second << endl;
  for (int i = 0; i < vag2.size(); i++) cout << vag2[i].second << endl;
}
