H,W=map(int,input().split())
S = [list(str(input())) for i in range(H)]
judge=True
for i in range(H):
    for j in range(W):
        if S[i][j]=='#':
            judge1=True
            judge2=True
            judge3=True
            judge4=True
            
            try:S[i][j-1]
            except IndexError:judge1=False
            else:
                if S[i][j-1]=='.':
                    judge1=False
                    
            try:S[i][j+1]
            except IndexError:judge2=False
            else:
                if S[i][j+1]=='.':
                    judge2=False
                    
            try:S[i+1][j]
            except IndexError:judge3=False
            else:
                if S[i+1][j]=='.':
                    judge3=False
                    
            try:S[i-1][j]
            except IndexError:judge4=False
            else:
                if S[i-1][j]=='.':
                    judge4=False

            if judge1==False and judge2==False and judge3==False and judge4==False:
                judge=False
                break

    if judge==False:break


print(judge)