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
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log, pi, sin
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


def valid(a, b):
    return 0 <= a < n and 0 <= b < m


def check(a):
    q = deque()
    q.append(a)
    vis[tuple(a)] = True
    while q:
        t1, t2 = q.pop()
        for i in range(4):
            a, b = t1+x[i], t2 + y[i]
            if valid(a, b) and not vis[(a, b)] and mat[a][b] == 'B':
                parent[(a, b)] = (t1, t2)
                q.append([a, b])
                vis[(a, b)] = True


def cmp(a, b):
    if a[0] < b[0]:
        return -1
    if b[0] < a[0]:
        return -1
    if a[1] < b[1]:
        return -1
    return 1


n, m = sp()
mat = []
cnt = 0
for i in range(n):
    mat.append(data())
    cnt += mat[i].count('B')
x, y = [-1, 1, 0, 0], [0, 0, -1, 1]
if cnt <= 1:
    out("YES")
    exit()
r = True
blacks = []
for i in range(n):
    for j in range(m):
        if mat[i][j] == 'B':
            blacks.append([i, j])
for i in range(len(blacks)-1):
    parent = dd(tuple)
    vis = dd(int)
    check(blacks[i])
    # print(parent)
    for j in range(i+1, len(blacks)):
        # print(parent[tuple(blacks[j])], blacks[j], blacks[i])
        if parent[tuple(blacks[j])] == ():
            out("NO")
            exit()
        path = []
        temp = blacks[j][:]
        while temp != ():
            path.append(temp)
            temp = parent[tuple(temp)]
        path = sorted(path, key=cmp_to_key(cmp))
        cnt = 0
        for k in range(1, len(path)):
            if path[i][0] != path[i-1][0] and path[i][1] != path[i-1][1]:
                cnt += 1
        if cnt > 1:
            out("NO")
            exit()
out("YES")
