#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const double eps = (double)1e-9;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 100500;
int n, m;
struct edge {
  int x, y, id;
  edge(){};
  edge(int a, int b, int c) : x(a), y(b), id(c){};
};
vector<edge> e1, e2;
struct dsu {
  int p[N], h[N];
  inline void init() {
    memset(p, 0, sizeof(p));
    memset(h, 0, sizeof(h));
    for (int i = 1; i <= n; i++) p[i] = i;
  }
  int get(int v) { return (v == p[v] ? v : p[v] = get(p[v])); }
  inline bool unite(int x, int y) {
    x = get(x), y = get(y);
    if (x == y) return 0;
    if (h[x] > h[y]) swap(x, y);
    p[x] = y, h[y] += h[x] == h[y];
    return 1;
  }
} dsu1, dsu2;
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  if (n % 2 == 0) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    edge e = edge(x, y, i);
    if (c == 'S')
      e1.push_back(e);
    else
      e2.push_back(e);
  }
  dsu1.init();
  dsu2.init();
  int cnt1 = 0, cnt2 = 0;
  for (auto i : e1) {
    int x = i.x, y = i.y;
    cnt1 += (dsu1.unite(x, y));
  }
  vector<int> ans;
  for (auto i : e2) {
    int x = i.x, y = i.y;
    if (dsu1.unite(x, y)) {
      ans.push_back(i.id);
      dsu2.unite(x, y);
      cnt2++;
    }
  }
  if (cnt1 + cnt2 != n - 1) {
    cout << -1;
    return 0;
  }
  for (auto i : e2) {
    if (cnt1 == cnt2) break;
    int x = i.x, y = i.y;
    if (dsu2.unite(x, y)) {
      ans.push_back(i.id);
      cnt1--, cnt2++;
    }
  }
  if (cnt1 != cnt2) {
    cout << -1;
    return 0;
  }
  for (auto i : e1) {
    int x = i.x, y = i.y;
    if (dsu2.unite(x, y)) ans.push_back(i.id);
  }
  cout << n - 1 << "\n";
  for (auto i : ans) cout << i << " ";
  return 0;
}
