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 JAVA):

Solution:
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;


public class E {
    final static Scanner sc = new Scanner(System.in);
    
    public static void main(String[] args) {
        final int n = sc.nextInt();
        final int m = sc.nextInt();
        
        if(n%2 == 0) {
            System.out.println(-1);
            return;
        }
        
        int[] count = new int[2];
        int[][] e = new int[m][3];
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < 2; j++) {
                e[i][j] = sc.nextInt() - 1;
            }
            e[i][2] = sc.next().charAt(0) == 'S' ? 0 : 1;
            count[e[i][2]]++;
        }
        
        int[][] a = new int[2][], b = new int[2][], idx = new int[2][];
        for(int i = 0; i < 2; i++) {
            a[i] = new int[count[i]];
            b[i] = new int[count[i]];
            idx[i] = new int[count[i]];
            for(int j = 0, k = 0; j < m; j++) {
                if(e[j][2] == i) {
                    a[i][k] = e[j][0];
                    b[i][k] = e[j][1];
                    idx[i][k] = j + 1;
                    k++;
                }
            }
        }
        
        boolean[][] res = new TwoTypeEdgeSpanningTree().run(n, a, b, new int[]{ (n-1)/2, (n-1)/2 } );
        if(res == null) {
            System.out.println(-1);
            return;
        }

        System.out.println(n-1);
        for(int i = 0; i < 2; i++)
            for(int j = 0; j < res[i].length; j++)
                if(res[i][j])
                    System.out.print(idx[i][j] + " ");
        System.out.println();
    }
    
    static public class TwoTypeEdgeSpanningTree {
        public boolean[][] run(int vertexSize, int[][] a, int[][] b, int[] uselen) {
            assert(a.length == 2 && b.length == 2 && uselen.length == 2);
            
            for(int i = 0; i < 2; i++) {
                assert(a[i].length == b[i].length);
            }
            
            assert(uselen[0] + uselen[1] == vertexSize - 1);
            
            int len1 = 0, len2 = 0;
            boolean[] used1 = new boolean[a[0].length];
            boolean[] used2 = new boolean[a[1].length];
            UnionFind uf1 = new UnionFind(vertexSize), uf2 = new UnionFind(vertexSize);
            for(int i = 0; i < a[0].length; i++) {
                if(!uf1.same(a[0][i], b[0][i])) {
                    uf1.union(a[0][i], b[0][i]);
                    used1[i] = true;
                    len1++;
                }
            }
            
            for(int i = 0; i < a[1].length; i++) {
                if(!uf1.same(a[1][i], b[1][i])) {
                    uf1.union(a[1][i], b[1][i]);
                    uf2.union(a[1][i], b[1][i]);
                    len2++;
                    used2[i] = true;
                }
            }
            
            for(int i = 0; i < a[1].length && len2 < uselen[1]; i++) {
                if(!uf2.same(a[1][i], b[1][i])) {
                    uf2.union(a[1][i], b[1][i]);
                    len2++;
                    len1--;
                    used2[i] = true;
                }
            }
            
            if(len1 != uselen[0] || len2 != uselen[1]) {
                return null;
            }
            
            Arrays.fill(used1, false);
            UnionFind uf = new UnionFind(vertexSize);
            for(int i = 0; i < a[1].length; i++) {
                if(used2[i]) {
                    uf.union(a[1][i], b[1][i]);
                }
            }
            for(int i = 0; i < a[0].length; i++) {
                if(!uf.same(a[0][i], b[0][i])) {
                    uf.union(a[0][i], b[0][i]);
                    used1[i] = true;
                }
            }
            
            return new boolean[][] { used1, used2 };
        }

        static class UnionFind {
            private int[] data;
            
            public UnionFind(int size) {
                data = new int[size];
                clear();
            }
            
            public void clear() { Arrays.fill(data, -1); }
            
            public int root(int x) { return data[x] < 0 ? x : (data[x] = root(data[x])); }
            
            public void union(int x, int y) {
                if((x = root(x)) != (y = root(y))) {
                    data[x] += data[y];
                    data[y] = x;
                }
            }
            
            public boolean same(int x, int y) { return root(x) == root(y); }
            public int size(int x) { return -data[root(x)]; }
        }
    }

}