#include <bits/stdc++.h>
int n, m, edgesum;
struct data {
  int st, en;
  char who;
  int k, idx;
};
data edge[100010];
struct data2 {
  int par, dep;
};
data2 group[1010];
int print[100010], pc;
void input(void) {
  int i;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d %c", &edge[i].st, &edge[i].en, &edge[i].who);
    if (edge[i].who == 'S')
      edge[i].k = -1;
    else
      edge[i].k = 1;
    edge[i].idx = i;
  }
}
void init(void) {
  int i;
  for (i = 1; i <= n; i++) {
    group[i].dep = 1;
    group[i].par = i;
  }
}
int find(int t) {
  for (;;) {
    if (group[t].par == t) return t;
    t = group[t].par;
  }
}
void uunion(int a, int b) {
  if (group[a].dep > group[b].dep) {
    group[b].par = a;
  } else if (group[a].dep < group[b].dep) {
    group[a].par = b;
  } else {
    group[b].par = a;
    group[a].dep++;
  }
}
void process(void) {
  int i, r1, r2, need, con = 0;
  if (n % 2 == 0) {
    printf("-1\n");
    return;
  }
  init();
  for (i = 1; i <= m; i++) {
    if (edge[i].k == -1) {
      r1 = find(edge[i].st), r2 = find(edge[i].en);
      if (r1 == r2) continue;
      con++;
      uunion(r1, r2);
    }
  }
  if (con < n / 2) {
    printf("-1\n");
    return;
  }
  for (i = 1; i <= m; i++) {
    if (edge[i].k == 1) {
      r1 = find(edge[i].st), r2 = find(edge[i].en);
      if (r1 == r2) continue;
      con++;
      uunion(r1, r2);
      print[++pc] = i;
    }
  }
  if (con < n - 1) {
    printf("-1\n");
    return;
  }
  init();
  need = n / 2;
  for (i = 1; i <= pc; i++) {
    r1 = find(edge[print[i]].st), r2 = find(edge[print[i]].en);
    if (r1 == r2) continue;
    uunion(r1, r2);
    need--;
  }
  for (i = 1; i <= m; i++) {
    if (edge[i].k == 1) {
      r1 = find(edge[i].st), r2 = find(edge[i].en);
      if (r1 == r2) continue;
      uunion(r1, r2);
      need--;
      print[++pc] = i;
      if (!need) break;
    }
  }
  if (need != 0) {
    printf("-1\n");
    return;
  }
  need = n / 2;
  for (i = 1; i <= m; i++) {
    if (edge[i].k == -1) {
      r1 = find(edge[i].st), r2 = find(edge[i].en);
      if (r1 == r2) continue;
      uunion(r1, r2);
      print[++pc] = i;
      need--;
      if (!need) break;
    }
  }
  printf("%d\n", pc);
  for (i = 1; i <= pc; i++) {
    printf("%d ", print[i]);
  }
}
int main(void) {
  input();
  process();
  return false;
}
