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

public class Main {

    private static class GV {
        private int n, m;
        private List<Edge>[] map;
    }

    private static class MyVector extends ArrayList<Edge> {
    }

    private static GV gv = new GV();

    public static void main(String[] args) throws IOException {
        Reader in = new Reader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        gv.n = in.nextInt();
        gv.m = in.nextInt();

        gv.map = new MyVector[gv.n + 1];
        for (int i = 1; i <= gv.n; i++) {
            gv.map[i] = new MyVector();
        }

        for (int i = 0; i < gv.m; i++) {
            int x = in.nextInt();
            int y = in.nextInt();
            int z = in.next().toCharArray()[0] == 'R' ? 1 : -1;

            gv.map[x].add(new Edge(y, z));
            gv.map[y].add(new Edge(x, z));
        }

        TwoAns twoAns = new TwoAns(gv.n, 1);
        for (int i = 1; i <= gv.n; i++) {
            if (!twoAns.visited[i]) {
                dfs(i, twoAns, true, false);
                twoAns.renew();
            }
        }

        TwoAns twoAns2 = new TwoAns(gv.n, -1);
        for (int i = 1; i <= gv.n; i++) {
            if (!twoAns2.visited[i]) {
                dfs(i, twoAns2, true, false);
                twoAns2.renew();
            }
        }

        Ans result = Ans.chose(twoAns.a, twoAns2.a);

        if (result == null) {
            out.println(-1);
        } else {
            result.show(out);
        }

        out.flush();
        in.close();
        out.close();
    }


    private static void dfs(int now, TwoAns ans, boolean c1, boolean c2) {
        if (c1) {
            ans.a1.ans.add(now);
        }
        if (c2) {
            ans.a2.ans.add(now);
        }
        ans.visited[now] = true;
        List<Edge> edges = gv.map[now];
        for (Edge edge : edges) {
            int next = edge.next;
            if (!ans.visited[next]) {
                if (edge.color == ans.aim) {
                    dfs(next, ans, c1, c2);
                } else {
                    dfs(next, ans, !c1, !c2);
                }
            } else {
                if (edge.color == ans.aim) {
                    ans.a1.ok &= ans.a1.ans.contains(next) == c1;
                    ans.a2.ok &= ans.a2.ans.contains(next) == c2;
                } else {
                    ans.a1.ok &= ans.a1.ans.contains(next) != c1;
                    ans.a2.ok &= ans.a2.ans.contains(next) != c2;
                }
            }

        }
    }

    private static class TwoAns {
        int aim;
        Ans a1 = new Ans(), a2 = new Ans(), a = new Ans();
        boolean[] visited;

        TwoAns(int n, int aim) {
            this.visited = new boolean[n + 1];
            this.aim = aim;
        }

        void renew() {
            Ans now = Ans.chose(a1, a2);
            if (now != null) {
                a.ok &= now.ok;
                a.ans.addAll(now.ans);
            } else {
                a.ok = false;
            }

            a1 = new Ans();
            a2 = new Ans();
        }

        Ans getAns() {
            return Ans.chose(a1, a2);
        }
    }

    private static class Ans {
        boolean ok;
        Set<Integer> ans;

        Ans() {
            this.ok = true;
            ans = new HashSet<>();
        }

        static Ans chose(Ans a, Ans b) {
            if (bad(a) && bad(b)) {
                return null;
            } else if (bad(a)) {
                return b;
            } else if (bad(b)) {
                return a;
            } else if (a.ans.size() < b.ans.size()) {
                return a;
            } else {
                return b;
            }
        }

        static boolean bad(Ans ans) {
            return ans == null || !ans.ok;
        }

        void show(PrintWriter out) {
            out.println(this.ans.size());
            for (Integer now : this.ans) {
                out.print(now + " ");
            }
        }
    }

    private static class Edge {
        int next, color;

        Edge(int next, int color) {
            this.next = next;
            this.color = color;
        }
    }

    static class Reader {
        BufferedReader reader;
        StringTokenizer st;

        Reader(InputStreamReader stream) {
            reader = new BufferedReader(stream);
            st = null;
        }

        void close() throws IOException {
            reader.close();
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

        String nextLine() throws IOException {
            return reader.readLine();
        }

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

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

    }
}