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.
# from usefull_stuff import basic_input
# basic_input("""
# 5 5
# WBBBW
# WBBBW
# WBBWW
# WBBBW
# WWWWW
# """)

def solve():
    n, m = map(int, input().split())
    grid = [list(map(int, input().translate({ord("W"): ord("0"), ord("B"): ord("1")}))) for _ in range(n)]

    def dfs(y, x):
        grid[y][x] = 2
        moves = [(-1, 0), (0, -1), (0, 1), (1, 0)]
        for move_y, move_x in moves:
            new_y, new_x = y + move_y, x + move_x
            if new_y < n and new_y >= 0 and \
                new_x < m and new_x >= 0 and \
                    grid[new_y][new_x] == 1:
                dfs(new_y, new_x)


    for y, row in enumerate(grid):
        b = True
        for x, t in enumerate(row):
            if t == 1:
                dfs(y, x)
                break
        else:
            b = False
        if b:
            break


    is_connected = False
    for y, row in enumerate(grid):
        b = True
        for x, t in enumerate(row):
            if t == 1:
                break
        else:
            b = False
        if b:
            break
    else:
        is_connected = True
    
    if not is_connected:
        return False
    
    hole_in_row = True
    for row in grid:
        found_end = False
        b = True
        for x, item in enumerate(row):
            if item == 2:
                if found_end:
                    break
                if x < m and row[x+1] == 0:
                    found_end = True
        else:
            b = False
        if b:
            break
    else:
        hole_in_row = False
    
    if hole_in_row:
        return False
    
    #
    hole_in_column = True
    for x in range(m):
        found_end = False
        b = True
        for y in range(n):
            item = grid[y][x]
            if item == 2:
                if found_end:
                    break
                if y < n and grid[y+1][x] == 0:
                    found_end = True
        else:
            b = False
        if b:
            break
    else:
        hole_in_column = False
    
    if hole_in_column:
        return False

    return True

print("YES" if solve() else "NO")