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
import os.path
 
if(os.path.exists('input.txt')) :
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")
    sys.stderr = open("error.txt", "w")
    
depth = 1000000
mod = 1000000007 
lim = mod * mod
sys.setrecursionlimit(depth) 
 
linp = lambda: list(minp())
minp = lambda: map(int, input().split())
 
from math import inf, ceil, sqrt, log2, gcd
from collections import defaultdict, deque
 
dd = lambda x: defaultdict(lambda: x)
dxy = [(1, 0),(-1, 0),(0, 1),(0, -1)]

def valid(x, y) :
    if x < 0 or x >= n : return False
    if y < 0 or y >= m : return False
    if vis[x][y] : return False
    if g[x][y] == 'W' : return False
    return True

def dfs(x, y) :
    ans, vis[x][y] = 1, True
    for e in dxy :
        if valid(x+e[0], y+e[1]) : 
            ans += dfs(x+e[0], y+e[1])
    return ans

def check(p1, p2) :
    (x1, y1), (x2, y2) = p1, p2
    if all([g[i][y1] == 'B' for i in range(x1, x2+1)]) and all([g[x2][i] == 'B' for i in range(min(y1, y2), max(y1, y2)+1)]) :
        return True
    if all([g[x1][i] == 'B' for i in range(min(y1, y2), max(y1, y2)+1)]) and all([g[i][y2] == 'B' for i in range(x1, x2+1)]) :
        return True
    return False

def solve(d) :
    d.sort(key=lambda x: (x[0], x[1]))
    for i in range(len(d)) :
        for j in range(i+1, len(d)) :
            if not check(d[i], d[j]) :
                return False
    return True

n, m = minp()
g, b, i, j = list(), 0, -1, -1
for k in range(n) :
    s = str(input())
    g.append(s)
    b += s.count('B')
    if 'B' in s :
        i, j = k, s.index('B')
if i == -1 : 
    print("YES")
    exit()
vis = [[False for _ in range(m)] for _ in range(n)]
if b != dfs(i, j) :
    print("NO")
    exit()
d = list()
for i in range(n) :
    for j in range(m) :
        if g[i][j] == 'B' :
            d.append((i, j))

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