import numpy as np
from scipy.sparse.csgraph import dijkstra

@np.vectorize
def trans(s):
    return 1 if s == "#" else 0

H, W = map(int, input().split())
S = np.array([trans([w for w in input()]) for _ in range(H)]).flatten()

def next_point(i, j, H, W, S):
    if S[i] != S[j]:
        if i == j + 1 and i % W != 0:
            return 2
        elif i == j - 1 and j % W != 0:
            return 2
        elif i == j + W:
            return 2
        elif i == j - W:
            return 2
        else:
            return 1
    else:
        return 0

G = np.array([[next_point(i, j, H, W, S) for j in range(len(S))] for i in range(len(S))])
connections = dijkstra(G >= 2)
c = (connections < np.inf) * G >= 1
print(int(np.sum(c) / 2))