Problem: After Santa Claus and his assistant Elf delivered all the presents and made all the wishes come true, they returned to the North Pole and found out that it is all covered with snow. Both of them were quite tired and they decided only to remove the snow from the roads connecting huts. The North Pole has n huts connected with m roads. One can go along the roads in both directions. 

The Elf offered to split: Santa Claus will clear up the wide roads and the Elf will tread out the narrow roads. For each road they decided who will clear it: Santa Claus or the Elf. To minimize the efforts they decided to clear the road so as to fulfill both those conditions: 

  * between any two huts should exist exactly one simple path along the cleared roads; 
  * Santa Claus and the Elf should clear the same number of roads. 



At this point Santa Claus and his assistant Elf wondered which roads should they clear up?

Input

The first input line contains two positive integers n and m (1 ≤ n ≤ 103, 1 ≤ m ≤ 105) — the number of huts and the number of roads. Then follow m lines, each of them contains a road description: the numbers of huts it connects — x and y (1 ≤ x, y ≤ n) and the person responsible for clearing out this road ("S" — for the Elf or "M" for Santa Claus). It is possible to go on each road in both directions. Note that there can be more than one road between two huts and a road can begin and end in the same hut.

Output

Print "-1" without the quotes if it is impossible to choose the roads that will be cleared by the given rule. Otherwise print in the first line how many roads should be cleared and in the second line print the numbers of those roads (the roads are numbered from 1 in the order of occurrence in the input). It is allowed to print the numbers of the roads in any order. Each number should be printed exactly once. As you print the numbers, separate them with spaces.

Examples

Input

1 2
1 1 S
1 1 M


Output

0



Input

3 3
1 2 S
1 3 M
2 3 S


Output

2
2 1 


Input

5 6
1 1 S
1 2 M
1 3 S
1 4 M
1 5 M
2 2 S


Output

-1

Note

A path is called simple if all huts on it are pairwise different.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int C = 100001;
vector<vector<int> > tr1(C), tr2(C), e1(C), e2(C), eT1(C), eT2(C);
int ij1[C], ij2[C], a, b, n, m;
int pr[C], ran[C];
void make_set(int x) { pr[x] = x, ran[x] = 0; }
int find_set(int x) {
  if (x != pr[x]) pr[x] = find_set(pr[x]);
  return pr[x];
}
void find_union(int a, int b) {
  int x = find_set(a), y = find_set(b);
  if (ran[x] > ran[y])
    pr[y] = x;
  else
    pr[x] = y;
  if (ran[x] == ran[y]) ran[y]++;
}
int pom[C], pom2[C], pom3[C], pom4[C];
void Sebasort(int tab[], int tab2[], int tab3[], int tab4[], int l, int r) {
  int lim = 2, limi = l + 1, limj = l + 2, j = limi, i = l, k = l;
  while (lim / 2 <= r - l + 1) {
    while (i <= r) {
      if (limj > r) limj = r + 1;
      if ((j < limj && tab[j] < tab[i]) || i >= limi)
        pom[k] = tab[j], pom2[k] = tab2[j], pom3[k] = tab3[j],
        pom4[k] = tab4[j], j++;
      else
        pom[k] = tab[i], pom2[k] = tab2[i], pom3[k] = tab3[i],
        pom4[k] = tab4[i], i++;
      k++;
      if (i == limi && j == limj) limi += lim, limj += lim, i = j, j = limi;
    }
    for (i = l; i <= r; i++)
      tab[i] = pom[i], tab2[i] = pom2[i], tab3[i] = pom3[i], tab4[i] = pom4[i];
    lim *= 2, limi = l + lim / 2, limj = l + lim, j = limi, i = k = l;
  }
}
int f1[C], f2[C], f3[C], f4[C], cor = 0;
int create_mst(int f1[], int f2[], int f3[], int n, int m,
               vector<vector<int> > &tr, vector<vector<int> > &e,
               vector<vector<int> > &eT, int ij[]) {
  int i, a, b, w = 0;
  cor = 0;
  for (i = 1; i <= n; i++) make_set(i);
  Sebasort(f3, f2, f1, f4, 0, m - 1);
  for (i = 0; i < m; i++) {
    a = find_set(f1[i]), b = find_set(f2[i]);
    if (a != b) {
      find_union(a, b);
      a = f1[i], b = f2[i];
      tr[a].push_back(b), tr[b].push_back(a);
      e[a].push_back(f4[i]), e[b].push_back(f4[i]);
      eT[a].push_back(f3[i]), eT[b].push_back(f3[i]);
      w += f3[i], cor++;
      ij[a]++, ij[b]++;
    }
  }
  return w;
}
int main() {
  int i, ax, ay, j;
  char k;
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    getchar(), k = getchar();
    f1[i] = a, f2[i] = b, f4[i] = i;
    if (k == 'M') f3[i] = 1;
  }
  ax = create_mst(f1, f2, f3, n, m, tr1, e1, eT1, ij1);
  for (i = 0; i < m; i++) f3[i] = 1 - f3[i];
  ay = create_mst(f1, f2, f3, n, m, tr2, e2, eT2, ij2);
  if (n % 2 == 0 || n / 2 < ax || n / 2 < ay || cor < n - 1) {
    printf("-1\n");
    return 0;
  }
  printf("%d\n", n - 1);
  for (i = 1; i <= n; i++) make_set(i);
  cor = 0;
  for (i = 1; i <= n; i++) {
    for (j = 0; j < ij1[i]; j++) {
      if (eT1[i][j] == 1) {
        a = find_set(i), b = find_set(tr1[i][j]);
        if (a != b) {
          find_union(a, b);
          printf("%d ", e1[i][j] + 1);
          cor++;
        }
      }
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j < ij2[i]; j++) {
      if (eT2[i][j] == 0) {
        if (cor == n / 2) break;
        a = find_set(i), b = find_set(tr2[i][j]);
        if (a != b) {
          find_union(a, b);
          printf("%d ", e2[i][j] + 1);
          cor++;
        }
      }
    }
    if (cor == n / 2) break;
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j < ij1[i]; j++) {
      if (eT1[i][j] == 0) {
        a = find_set(i), b = find_set(tr1[i][j]);
        if (a != b) {
          find_union(a, b);
          printf("%d ", e1[i][j] + 1);
        }
      }
    }
  }
  return 0;
}