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


def readline():
    return sys.stdin.readline().strip()


def read(t=int):
    s = sys.stdin.readline()
    return list(map(t, s.strip().split(' ')))


def readint():
    return read()[0]


def go():
    n, m = read()
    g = []
    totalblack = 0
    for i in range(n):
        s = readline()
        g += [s]
        totalblack += s.count("B")

    cnt = 0
    vis = {}
    # def dfs(r,c):
    #     if (r,c) in vis:
    #         return
    #     if g[r][c] != "B":
    #         return
    #     vis[(r,c)] = cnt
    #     for i,j in [(r-1,c),(r+1,c),(r,c-1),(r,c+1)]:
    #         if 0 <= i < n and 0 <= j < m:
    #             dfs(i,j)
    dr = [1, -1, 0, 0]
    dc = [0, 0, 1, -1]

    haha = 0
    vis = {}
    cao = {}

    def fb(r, c, now_dir, could_turn):
        # print(r, c)
        nonlocal haha
        if (r, c) in vis:
            return
        vis[(r, c)] = 1
        # print(r,c)
        if (r,c) not in cao:
            haha += 1
            cao[(r,c)]=1
        for i in range(4):
            nr = dr[i]+r
            nc = dc[i]+c
            if 0 <= nr < n and 0 <= nc < m and (nr, nc) not in vis and g[nr][nc] == "B":
                if i == now_dir or now_dir is None:
                    fb(nr, nc, i, could_turn)
                elif could_turn:
                    fb(nr, nc, i, False)
        del vis[(r, c)]
        # else:
        #     i = now_dir
        #     nr = dr[i]+r
        #     nc = dc[i]+c
        #     if 0 <= nr < n and 0 <= nc < m and (nr, nc) not in vis and g[nr][nc] == "B":
        #         fb(nr, nc, now_dir)

    for r in range(n):
        for c in range(m):
            if g[r][c] == "B":
                # vis = {}
                cao = {}
                haha = 0
                fb(r, c, None, True)
                # print(haha, totalblack, vis)
                if haha != totalblack:
                    raise "Asdasd"
            # if (r,c) not in vis and g[r][c] == "B":
                # dfs(r,c)
                # cnt+=1
    # if cnt>1:
    #     raise "Asdasd"


try:
    go()
    print("YES")
except:
    print("NO")
