#include <bits/stdc++.h>
using namespace std;
bool edge[101000];
char t[101000];
int n, e, S, M;
int e1[101000], e2[101000];
struct dsu {
  int c;
  int p[1010], h[1010];
  dsu() {
    c = 0;
    memset(h, 0, sizeof h);
    for (int i = 1; i < 1010; i++) p[i] = i;
  }
  int find(int x) {
    if (x == p[x]) return x;
    return p[x] = find(p[x]);
  }
  bool Union(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return false;
    c++;
    if (h[x] > h[y]) {
      p[y] = x;
      return true;
    }
    if (h[x] < h[y]) {
      p[x] = y;
      return true;
    }
    if (h[x] == h[y]) {
      p[y] = x;
      h[x]++;
      return true;
    }
  }
};
inline void imp() {
  cout << -1 << endl;
  exit(0);
}
int main() {
  cin >> n >> e;
  if (n % 2 == 0) imp();
  dsu ss, mm;
  for (int i = 1; i <= e; i++) {
    cin >> e1[i] >> e2[i] >> t[i];
    if (t[i] == 'S') edge[i] = ss.Union(e1[i], e2[i]);
    if (t[i] == 'M') edge[i] = mm.Union(e1[i], e2[i]);
  }
  int need = (n - 1) / 2;
  if (ss.c < need || mm.c < need) imp();
  dsu res;
  vector<int> ans;
  for (int i = 1; i <= e; i++)
    if (t[i] == 'M' && edge[i]) {
      bool flag = ss.Union(e1[i], e2[i]);
      if (flag) {
        res.Union(e1[i], e2[i]);
        ans.push_back(i);
      }
    }
  for (int i = 1; i <= e; i++)
    if (t[i] == 'M' && edge[i] && res.c < need)
      if (res.Union(e1[i], e2[i])) ans.push_back(i);
  for (int i = 1; i <= e; i++)
    if (t[i] == 'S' && edge[i])
      if (res.Union(e1[i], e2[i])) ans.push_back(i);
  cout << need * 2 << endl;
  for (int i = 0; i < 2 * need; i++) cout << ans[i] << ' ';
  cout << endl;
  return 0;
}
