Consider an *n* × *m* grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path.

You're given a painted grid in the input. Tell Lenny if the grid is convex or not.
The first line of the input contains two integers *n* and *m* (1 ≤ *n*, *m* ≤ 50) — the size of the grid. Each of the next *n* lines contains *m* characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid.

It's guaranteed that the grid has at least one black cell.
import numpy as np


def check_row(row):
    was_1 = False
    was_1_0 = False
    was_1_0_1 = False

    for elem in row:
        if elem == 1:
            was_1 = True
            if was_1_0:
                was_1_0_1 = True
        if elem == 0:
            if was_1:
                was_1_0 = True

    return not was_1_0_1


def check_rows(mat):
    for row in mat:
        if not check_row(row):
            return False
    return True


def bfs(mat, was, start):
    queue = []
    queue.insert(len(queue), start)

    while queue:
        current = queue.pop(0)
        was.add(current)

        for d in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            next = current + d
            if next not in was:
                queue.insert(len(queue), next)


def solve(n, m, mat):
    if not check_rows(mat):
        return False
    if not check_rows(mat.T):
        return False

    components_number = 0
    was = set()
    for i in range(n):
        for j in range(m):
            if (i, j) not in was:
                bfs(mat, was, (i, j))
                components_number += 1
    if components_number > 1:
        return False

    return True


def run():
    n, m = map(int, input().split())

    mat = np.zeros((n, m), dtype=int)

    for i in range(n):
        line = input()
        for j in range(m):
            mat[i, j] = 1 if line[j] == 'B' else 0

    return solve(n, m, mat)


print('YES') if run() else print('NO')