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.io.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				timeStart = System.currentTimeMillis();
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					
					long prevTime = System.currentTimeMillis();
					new Main().run();
					System.err.println("Total time: " + (System.currentTimeMillis() - prevTime) + " ms");
					System.err.println("Memory status: " + memoryStatus());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start(); 
	}

	static long timeStart;	
	
	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
		in.close();
	}
	
	/*************************************************************** 
	 * Solution
	 **************************************************************/
	
//	final int IT = 100;
	final long MAXTIME = 1700;
	
	Random rnd = new Random(7777L);
	
	void solve() throws IOException  {
		int vNum = nextInt();
		int eNum = nextInt();
		Edge[] edges = new Edge [eNum];
		Edge[] black = new Edge [eNum];
		Edge[] white = new Edge [eNum];
		int bNum = 0;
		int wNum = 0;
		for (int i = 0; i < eNum; i++) { 
			int u = nextInt() - 1;
			int v = nextInt() - 1;
			edges[i] = new Edge(i, u, v); 
			boolean color = nextToken().charAt(0) == 'S';
			if (color) {
				black[bNum++] = edges[i];
			} else {
				white[wNum++] = edges[i];
			}
		}
		black = Arrays.copyOf(black, bNum);
		white = Arrays.copyOf(white, wNum);
		
		DSF dsf = new DSF(vNum);
		
		int[] ans = new int [vNum - 1];
		
		int K = (vNum - 1) / 2;
		
		if (vNum % 2 == 0 || black.length < K || white.length < K) {
			out.println(-1);
			return;
		}
		
		dsf.clear();
			
		int needB = K;
		int needW = K;
		int asz = 0;
		
		for (int i = 0; i < black.length; i++) {
			Edge e = black[i];
			dsf.union(e.u, e.v);
		}
		
		for (int i = 0; i < white.length && needW > 0; i++) {
			Edge e = white[i];
			if (dsf.union(e.u, e.v)) {
				needW--;
				ans[asz++] = e.id + 1;
			}
		}
		
		for (int i = 0; i < white.length && needW > 0; i++) {
			Edge e = white[i];
			if (dsf.union(e.u, e.v)) {
				out.println(-1);
				return;
			}
		}
		
		dsf.clear();
		
		for (int i = 0; i < asz; i++) {
			Edge e = edges[ans[i] - 1];
			dsf.union(e.u, e.v);
		}
		
		for (int i = 0; i < white.length && needW > 0; i++) {
			Edge e = white[i];
			if (dsf.union(e.u, e.v)) {
				needW--;
				ans[asz++] = e.id + 1;
			}
		}
		
		if (needW > 0) {
			out.println(-1);
			return;
		}
		
		for (int i = 0; i < black.length && needB > 0; i++) {
			Edge e = black[i];
			if (dsf.union(e.u, e.v)) {
				needB--;
				ans[asz++] = e.id + 1;
			}
		}
		
		if (needB > 0) {
			out.println(-1);
			return;
		}
		
		
		out.println(asz);
		printArray(ans);
	}

	class Edge {
		int id;
		int u;
		int v;

		Edge(int id, int u, int v) {
			this.id = id;
			this.u = u;
			this.v = v;
		}
	}
	
	class DSF {
		int[] set;
		
		DSF(int n) {
			set = new int [n];
		}

		void clear() {
			for (int i = 0; i < set.length; i++) {
				set[i] = i;
			}
		}
		
		int setOf(int i) {
			return i == set[i] ? i : (set[i] = setOf(set[i]));
		}
		
		boolean union(int i, int j) {
			i = setOf(i);
			j = setOf(j);
			
			if (i == j) {
				return false;
			}
			
			if (rnd.nextBoolean()) {
				set[i] = j;
			} else {
				set[j] = i;
			}
			
//			System.out.println("union " + i + " " +j);
			
			return true;
		}
	}
	
	/*************************************************************** 
	 * Input 
	 **************************************************************/
	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");
	
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	
	int[] nextIntArray(int size) throws IOException {
		int[] ret = new int [size];
		for (int i = 0; i < size; i++)
			ret[i] = nextInt();
		return ret;
	}
	
	long[] nextLongArray(int size) throws IOException {
		long[] ret = new long [size];
		for (int i = 0; i < size; i++)
			ret[i] = nextLong();
		return ret;
	}
	
	double[] nextDoubleArray(int size) throws IOException {
		double[] ret = new double [size];
		for (int i = 0; i < size; i++)
			ret[i] = nextDouble();
		return ret;
	}
	
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
	
	/*************************************************************** 
	 * Output 
	 **************************************************************/
	void printRepeat(String s, int count) {
		for (int i = 0; i < count; i++)
			out.print(s);
	}
	
	void printArray(int[] array) {
		if (array.length == 0) return;
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}
	
	void printArray(long[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}
	
	void printArray(double[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}
	
	void printArray(double[] array, String spec) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.printf(Locale.US, spec, array[i]);
		}
		out.println();
	}
	
	void printArray(Object[] array) {
		boolean blank = false;
		for (Object x : array) {
			if (blank) out.print(' '); else blank = true;
			out.print(x);
		}
		out.println();
	}
	
	@SuppressWarnings("rawtypes")
	void printCollection(Collection collection) {
		boolean blank = false;
		for (Object x : collection) {
			if (blank) out.print(' '); else blank = true;
			out.print(x);
		}
		out.println();
	}
	
	/*************************************************************** 
	 * Utility
	 **************************************************************/
	static String memoryStatus() {
		return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() >> 20) + "/" + (Runtime.getRuntime().totalMemory() >> 20) + " MB";
	}
	
	static void checkMemory() {
		System.err.println(memoryStatus());
	}
	
	static long prevTimeStamp = Long.MIN_VALUE;
	
	static void updateTimer() {
		prevTimeStamp = System.currentTimeMillis();
	}
	
	static long elapsedTime() {
		return (System.currentTimeMillis() - prevTimeStamp);
	}
	
	static void checkTimer() {
		System.err.println(elapsedTime() + " ms");
	}
}