#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000;
const int MAXM = 100 * 1000;
struct edge {
  int second, first, Id;
} em[MAXM + 10], es[MAXM + 10];
int mm, ms;
int n, m;
int p[2][MAX + 10];
int s[2][MAX + 10];
void read();
int find_P(bool, int);
bool join(bool, int, int);
void clear(bool);
vector<int> out;
void solve() {
  clear(0);
  clear(1);
  int size = 0;
  for (int i = 0; i < mm; i++)
    if (join(0, em[i].second, em[i].first)) size++;
  if (size < (n - 1) / 2) {
    cout << -1 << endl;
    exit(0);
  };
  for (int i = 0; i < ms; i++)
    if (join(0, es[i].second, es[i].first)) {
      join(1, es[i].second, es[i].first);
      out.push_back(es[i].Id);
    }
  if (size + (int)out.size() != n - 1) {
    cout << -1 << endl;
    exit(0);
  };
  for (int i = 0; i < ms && (int)out.size() < (n - 1) / 2; i++)
    if (join(1, es[i].second, es[i].first)) out.push_back(es[i].Id);
  if ((int)out.size() < (n - 1) / 2) {
    cout << -1 << endl;
    exit(0);
  };
  for (int i = 0; i < mm; i++)
    if (join(1, em[i].second, em[i].first)) out.push_back(em[i].Id);
}
int main() {
  read();
  if ((n - 1) & 1) {
    cout << -1 << endl;
    exit(0);
  };
  solve();
  cout << out.size() << endl;
  for (int i = 0; i < (int)out.size(); i++) cout << out[i] << " ";
  cout << endl;
}
void read() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int second, first;
    char c;
    cin >> second >> first >> c;
    second--;
    first--;
    if (c == 'M')
      em[mm++] = {second, first, i + 1};
    else
      es[ms++] = {second, first, i + 1};
  }
}
int find_P(bool k, int a) {
  if (p[k][a] == a) return a;
  return p[k][a] = find_P(k, p[k][a]);
}
void clear(bool k) {
  for (int i = 0; i < n; i++) {
    p[k][i] = i;
    s[k][i] = 1;
  }
}
bool join(bool k, int a, int b) {
  a = find_P(k, a);
  b = find_P(k, b);
  if (a == b) return false;
  if (s[b] > s[a]) swap(a, b);
  p[k][b] = a;
  s[k][a] += s[k][b];
  return true;
}
