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.BufferedInputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class P664D {

    private static class DSNode {

        public final int x;

        private DSNode parent;
        private int rank;

        public DSNode(int x) {
            this.x = x;
            this.parent = this;
            this.rank = 0;
        }

        public DSNode find() {
            DSNode node = this;
            while (node.parent != node) {
                final DSNode parent = node.parent;
                node.parent = parent.parent;
                node = parent;
            }
            return node;
        }

        public DSNode union(DSNode other) {
            DSNode node = this.find();
            other = other.find();
            if (node == other) {
                return node;
            }
            if (node.rank < other.rank) {
                final DSNode tmp = node;
                node = other;
                other = tmp;
            }
            other.parent = node;
            if (node.rank == other.rank) {
                node.rank++;
            }
            return node;
        }

        public boolean isRoot() {
            return this.parent == this;
        }
    }

    private static int[] toArray(final List<Integer> lst) {
        final int[] arr = new int[lst.size()];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = lst.get(i);
        }
        return arr;
    }

    private static int[][][] getDarts(int n, int m, int[][] edges) {
        final List<List<Integer>> e1 = new ArrayList<>(n);
        final List<List<Integer>> e2 = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            e1.add(new ArrayList<>());
            e2.add(new ArrayList<>());
        }
        for (int j = 0; j < m; j++) {
            if (edges[j][2] == 0) {
                e1.get(edges[j][0]-1).add(edges[j][1]-1);
                e1.get(edges[j][1]-1).add(edges[j][0]-1);
            } else {
                e2.get(edges[j][0]-1).add(edges[j][1]-1);
                e2.get(edges[j][1]-1).add(edges[j][0]-1);
            }
        }
        final int[][][] darts = new int[n][2][];
        for (int i = 0; i < n; i++) {
            final List<Integer> l1 = e1.get(i);
            darts[i][0] = toArray(e1.get(i));
            darts[i][1] = toArray(e2.get(i));
        }
        return darts;
    }

    private static List<Integer> coloring(int n, int m, int[][] edges) {
        final DSNode[] dsn = new DSNode[n];
        for (int i = 0; i < n; i++) {
            dsn[i] = new DSNode(i);
        }
        for (int j = 0; j < m; j++) {
            dsn[edges[j][0]-1].union(dsn[edges[j][1]-1]);
        }
        final List<DSNode> roots = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (dsn[i].isRoot()) {
                roots.add(dsn[i]);
            }
        }
        final int[][][] darts = getDarts(n, m, edges);
        List<Integer> best = null;
        for (int c = 0; c < 2; c++) {
            final boolean[] visited = new boolean[n];
            final List<Integer> mset = new ArrayList<>();
            boolean ok = true;
            outer:
            for (final DSNode d : roots) {
                final Set<Integer> s1 = new HashSet<>();
                final Set<Integer> s2 = new HashSet<>();
                s1.add(d.x);
                final Deque<Integer> deque = new ArrayDeque<>();
                deque.addLast(d.x);
                visited[d.x] = true;
                while (!deque.isEmpty()) {
                    final int i1 = deque.removeLast();
                    boolean c1 = s1.contains(i1);
                    final Set<Integer> t1 = c1 ? s1 : s2;
                    final Set<Integer> t2 = c1 ? s2 : s1;
                    for (int i2 : darts[i1][c]) {
                        if (t1.contains(i2)) {
                            ok = false;
                            break outer;
                        }
                        t2.add(i2);
                        if (!visited[i2]) {
                            deque.addLast(i2);
                            visited[i2] = true;
                        }
                    }
                    for (int i2 : darts[i1][(c+1) % 2]) {
                        if (t2.contains(i2)) {
                            ok = false;
                            break outer;
                        }
                        t1.add(i2);
                        if (!visited[i2]) {
                            deque.addLast(i2);
                            visited[i2] = true;
                        }
                    }
                }
                final Set<Integer> smin = s1.size() <= s2.size() ? s1 : s2;
                mset.addAll(smin);
            }
            if (ok) {
                if (best == null || mset.size() < best.size()) {
                    best = mset;
                }
            }
        }
        return best;
    }

    public static void main(String[] args) throws IOException {
        try {
            final FastReader fr = new FastReader(
                new BufferedInputStream(System.in));
            final int n = fr.readInt();
            final int m = fr.readInt();
            final int[][] edges = new int[m][3];
            for (int j = 0; j < m; j++) {
                edges[j][0] = fr.readInt();
                edges[j][1] = fr.readInt();
                edges[j][2] = (fr.readNonWs() == (byte) 'B') ? 0 : 1;
            }
            final List<Integer> col = coloring(n, m, edges);
            if (col == null) {
                System.out.println("-1");
            } else {
                final StringBuilder sb = new StringBuilder();
                sb.append(col.size());
                char ch = '\n';
                for (final int i : col) {
                    sb.append(ch).append(i+1);
                    ch = ' ';
                }
                System.out.println(sb);
            }
        } catch (Throwable t) {
            t.printStackTrace(System.out);
            System.exit(1);
        }
    }

    private static final void log(Object o) {
        System.err.println(o);
    }

    private static class FastReader implements Closeable {
        private static final byte B_SP = ' ';
        private static final byte B_CR = '\r';
        private static final byte B_LF = '\n';
        private static final byte B_0 = '0';
        private static final byte B_9 = '9';
        private static final byte B_DASH = '-';
        private static final byte B_EOF = -1;

        private final InputStream in;
        private byte prev;

        public FastReader(InputStream in) {
            this.in = in;
        }

        public byte read() throws IOException {
            return (prev = (byte) in.read());
        }

        public byte readNonWs() throws IOException {
            byte b;
            do {
                b = read();
            } while (b <= B_SP);
            return b;
        }

        public int readInt() throws IOException {
            byte b = readNonWs();
            final boolean neg = (b == B_DASH);
            if (neg) {
                b = read();
            }
            int i = (b - B_0);
            b = read();
            while (b >= B_0 && b <= B_9) {
                i = i * 10 + (b - B_0);
                b = read();
            }
            return neg ? -i : i;
        }

        public long readLong() throws IOException {
            byte b = readNonWs();
            final boolean neg = (b == B_DASH);
            if (neg) {
                b = read();
            }
            long i = (b - B_0);
            b = read();
            while (b >= B_0 && b <= B_9) {
                i = i * 10 + (b - B_0);
                b = read();
            }
            return neg ? -i : i;
        }

        public int readToken(byte[] tbuf) throws IOException {
            byte b = readNonWs();
            int i = 0;
            do {
                tbuf[i++] = b;
                b = read();
            } while (b >= B_SP);
            return i;
        }

        public int readLine(byte[] lbuf) throws IOException {
            byte b;
            if (prev == B_CR) {
                b = read();
                if (b == B_LF) {
                    b = read();
                }
            } else {
                b = read();
            }
            int i = 0;
            while (b >= B_SP) {
                lbuf[i++] = b;
                b = read();
            }
            return i;
        }

        @Override
        public void close() throws IOException {
            in.close();
        }
    }
}
