You are given an undirected graph that consists of n vertices and m edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges with an endpoint in this vertex change the color to blue, while all blue edges with an endpoint in this vertex change the color to red.

Find the minimum possible number of moves required to make the colors of all edges equal.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the number of vertices and edges, respectively.

The following m lines provide the description of the edges, as the i-th of them contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the indices of the vertices connected by the i-th edge, and a character ci (<image>) providing the initial color of this edge. If ci equals 'R', then this edge is initially colored red. Otherwise, ci is equal to 'B' and this edge is initially colored blue. It's guaranteed that there are no self-loops and multiple edges.

Output

If there is no way to make the colors of all edges equal output  - 1 in the only line of the output. Otherwise first output k — the minimum number of moves required to achieve the goal, then output k integers a1, a2, ..., ak, where ai is equal to the index of the vertex that should be used at the i-th move.

If there are multiple optimal sequences of moves, output any of them.

Examples

Input

3 3
1 2 B
3 1 R
3 2 B


Output

1
2 


Input

6 5
1 3 R
2 3 R
3 4 B
4 5 R
4 6 R


Output

2
3 4 


Input

4 5
1 2 R
1 3 R
2 3 B
3 4 B
1 4 B


Output

-1
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static boolean local = false;
    static FReader sc;
    static PrintWriter pw;

    public static void main(String args[]) throws FileNotFoundException {
        if (args.length != 0) {
            local = true;
            sc = new FReader("/Users/qjex/prj/jolymp/src/input.txt");
            try {
                pw = new PrintWriter(new FileOutputStream("/Users/qjex/prj/jolymp/src/output.txt"), false);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            sc = new FReader(System.in);
            pw = new PrintWriter(System.out);
        }
        solve();
        pw.close();
        sc.close();
    }


    static int n;
    static int[] used;
    static ArrayList<Pair>[] g;
    static ArrayList<Integer> cur = new ArrayList<Integer>();
    static ArrayList<Integer> cur1 = new ArrayList<Integer>();

    static boolean dfs(int v, int cl, int paint) {
        used[v] = cl;

        if (cl == 1) cur.add(v);
        else cur1.add(v);
        for (Pair to : g[v]) {
            int ncl = paint == to.second ? cl : (3 - cl);
            if (used[to.first] == 0) {
                if (!dfs(to.first, ncl, paint)) return false;
            } else {
                if (used[to.first] != ncl)
                    return false;
            }
        }
        return true;
    }

    static ArrayList<Integer> paint(int color) {
        ArrayList<Integer> res = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            if (used[i] == 0) {
                cur.clear();
                cur1.clear();
                if (dfs(i, 1, color)) {
                    if (cur.size() < cur1.size()) for (int v : cur) res.add(v);
                    else for (int v : cur1) res.add(v);
                } else {
                    return null;
                }
            }
        }
        return res;
    }

    public static void solve() {
        n = sc.nextInt();
        int m = sc.nextInt();
        g = new ArrayList[n];
        for (int i = 0; i < n; i++)
            g[i] = new ArrayList<Pair>();
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt(), b = sc.nextInt();
            String c = sc.next();
            a--;
            b--;
            int cl = c.equals("B") ? 1 : 2;
            g[a].add(new Pair(b, cl));
            g[b].add(new Pair(a, cl));
        }
        ArrayList<Integer> ans = null;
        used = new int[n];
        Arrays.fill(used, 0);
        ArrayList<Integer> b = paint(1);
        Arrays.fill(used, 0);
        ArrayList<Integer> r = paint(2);
        if (b != null && r != null) {
            if (b.size() < r.size()) ans = b;
            else ans = r;
        } else {
            if (b != null) ans = b;
            if (r != null) ans = r;
        }

        if (ans == null) {
            pw.print(-1);
            return;
        }
        pw.println(ans.size());
        for (int x : ans) pw.print((x + 1) + " ");
    }

}

class FReader {
    BufferedReader br;
    StringTokenizer st;

    FReader(String file) {
        try {
            br = new BufferedReader(new FileReader(file));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        st = new StringTokenizer("");
    }


    FReader(InputStream is) {
        br = new BufferedReader(new InputStreamReader(is));
        st = new StringTokenizer("");
    }

    String next() {
        try {
            while (!st.hasMoreElements()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    BigInteger nextBigInteger(){ return new BigInteger(next()); }

    public void close() {
        try {
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

class Pair implements Comparable<Pair> {

    public int first;
    public int second;

    public Pair(int first, int second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public int compareTo(Pair pairInt) {
        if (first > pairInt.first) return 1;
        if (first < pairInt.first) return -1;
        if (second > pairInt.second) return 1;
        return second == pairInt.second ? 0 : -1;
    }


    @Override
    public boolean equals(Object obj) {
        return obj instanceof Pair && compareTo((Pair) obj) == 0;
    }
}