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 sys
#sys.setrecursionlimit(10**7)
input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
############ ---- Input Functions ---- ############

def Convex_Shape():
    n,m = invr()

    row_pos = []
    col_pos = []
    full_matrix = []

    for row_index in range(n):
        row = insr()
        full_matrix.append(row)
        for col_index in range(m):
            if row[col_index] == 'B':
                row_pos.append(row_index)
                col_pos.append(col_index)
    
    #print(row_pos)
    #print(col_pos)
    number_of_black_squares = len(row_pos)

    is_convex = True 

    for i in range(number_of_black_squares):
        for j in range(i+1,number_of_black_squares):
            if is_convex:
                row_initial = row_pos[i]
                col_intial = col_pos[i]
                row_target = row_pos[j]
                col_target = col_pos[j]


                horizontal_steps = abs(row_target-row_initial)
                if row_target > row_initial:
                    dx = 1 
                else:
                    dx = -1 
                
                vertical_steps = abs(col_target - col_intial)
                if col_target > col_intial:
                    dy = 1 
                else:
                    dy = -1 
                
                path1_possible = True 
                path2_possible = True 

                r = row_initial
                c = col_intial
                for h in range(horizontal_steps):
                    r = r + dx 
                    if full_matrix[r][c] != 'B':
                        path1_possible = False 
                
                for v in range(vertical_steps):
                    c = c + dy 
                    if full_matrix[r][c] != 'B':
                        path1_possible = False 
                
                r = row_initial
                c = col_intial
                for v in range(vertical_steps):
                    c = c + dy 
                    if full_matrix[r][c] != 'B':
                        path2_possible = False 
                
                for h in range(horizontal_steps):
                    r = r + dx 
                    if full_matrix[r][c] != 'B':
                        path2_possible = False 
                
                if not path1_possible and not path2_possible:
                    is_convex = False 
    
    if is_convex:
        print("YES")
    else:
        print("NO")     
    return 



Convex_Shape()