import numpy as np

h, w = list(map(int, input().split()))

s = np.array([list(eval(input())) for _ in range(h)])

w1, w2 = np.array(["."]*h), np.array(["."]*(w+2))

s = np.hstack((w1.reshape(len(w1),1), s))

s = np.hstack((s, w1.reshape(len(w1),1)))

s = np.vstack((w2, s))

s = np.vstack((s, w2))

dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]

for i in range(1, h+1, 1):

    for j in range(1, w+1, 1):

        now = s[i][j]

        c = 0

        if now == ".":

            continue

        for d in range(4):

            x = j + dx[d]

            y = i + dy[d]

            if now == s[y][x]:

                c += 1

        if c == 0:

            print("No")

            exit()

print("Yes")
def main():

    h, w = list(map(int, input().split()))

    k = [["."]+list(eval(input()))+["."] for _ in range(h)]

    s = [[None]*(w+2) for _ in range(h+2)]

    s[0] = ["."]*(w+2)

    s[-1] = ["."]*(w+2)

    s[1:h+1] = k

    d = [[0, 1], [0, -1], [1, 0], [-1, 0]]

    for i in range(1, h+1):

        for j in range(1, w+1):

            if s[i][j] == ".":

                continue

            flag = True

            for (di, dj) in d:

                if s[i+di][j+dj] == "#":

                    flag = False

                    break

            if flag:

                print("No")

                return

    print("Yes")



if __name__ == "__main__":

    main()
import numpy as np

h, w = list(map(int, input().split()))
s = np.array([list(eval(input())) for _ in range(h)])
w1, w2 = np.array(["."] * h), np.array(["."] * (w + 2))
s = np.hstack((w1.reshape(len(w1), 1), s))
s = np.hstack((s, w1.reshape(len(w1), 1)))
s = np.vstack((w2, s))
s = np.vstack((s, w2))
dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]
for i in range(1, h + 1, 1):
    for j in range(1, w + 1, 1):
        now = s[i][j]
        c = 0
        if now == ".":
            continue
        for d in range(4):
            x = j + dx[d]
            y = i + dy[d]
            if now == s[y][x]:
                c += 1
        if c == 0:
            print("No")
            exit()
print("Yes")

def main():
    h, w = list(map(int, input().split()))
    k = [["."] + list(eval(input())) + ["."] for _ in range(h)]
    s = [[None] * (w + 2) for _ in range(h + 2)]
    s[0] = ["."] * (w + 2)
    s[-1] = ["."] * (w + 2)
    s[1 : h + 1] = k
    d = [[0, 1], [0, -1], [1, 0], [-1, 0]]
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if s[i][j] == ".":
                continue
            flag = True
            for (di, dj) in d:
                if s[i + di][j + dj] == "#":
                    flag = False
                    break
            if flag:
                print("No")
                return
    print("Yes")


if __name__ == "__main__":
    main()

-import numpy as np +def main(): +    h, w = list(map(int, input().split())) +    k = [["."] + list(eval(input())) + ["."] for _ in range(h)] +    s = [[None] * (w + 2) for _ in range(h + 2)] +    s[0] = ["."] * (w + 2) +    s[-1] = ["."] * (w + 2) +    s[1 : h + 1] = k +    d = [[0, 1], [0, -1], [1, 0], [-1, 0]] +    for i in range(1, h + 1): +        for j in range(1, w + 1): +            if s[i][j] == ".": +                continue +            flag = True +            for (di, dj) in d: +                if s[i + di][j + dj] == "#": +                    flag = False +                    break +            if flag: +                print("No") +                return +    print("Yes") -h, w = list(map(int, input().split())) -s = np.array([list(eval(input())) for _ in range(h)]) -w1, w2 = np.array(["."] * h), np.array(["."] * (w + 2)) -s = np.hstack((w1.reshape(len(w1), 1), s)) -s = np.hstack((s, w1.reshape(len(w1), 1))) -s = np.vstack((w2, s)) -s = np.vstack((s, w2)) -dx, dy = [1, 0, -1, 0], [0, 1, 0, -1] -for i in range(1, h + 1, 1): -    for j in range(1, w + 1, 1): -        now = s[i][j] -        c = 0 -        if now == ".": -            continue -        for d in range(4): -            x = j + dx[d] -            y = i + dy[d] -            if now == s[y][x]: -                c += 1 -        if c == 0: -            print("No") -            exit() -print("Yes") + +if __name__ == "__main__": +    main()