input = STDIN.read.split("\n")
f = input.shift.split(" ")
H = f[0].to_i
W = f[1].to_i

TABLE = input.map{|l| l.split("")}

$count  = 0

def check(i, j, checked = {}, prev = nil, passed_white = 0, passed_black = 0)
    if checked[i][j] == true
        return
    end
    if i == H && j == W
        return
    end

    c = TABLE[i][j]
    checked[i][j] = true

    if c == '#' && (prev == nil || prev == '.')
        check(i - 1, j, checked, '#') if i > 0
        check(i + 1, j, checked,'#') if i < (H - 1)
        check(i, j - 1, checked,'#') if j > 0
        check(i, j + 1, checked,'#') if j < (W - 1)
    end
    if c == '.' && prev == '#'
        $count = $count + 1
        check(i - 1, j, checked,'.') if i > 0
        check(i + 1, j, checked,'.') if i < (H - 1)
        check(i, j - 1,checked, '.') if j > 0
        check(i, j + 1,checked, '.') if j < (W - 1)
    end
end

for i in 0..(H - 1)
    for j in 0..(W - 1)
        check(i, j, Array.new(H).map{Array.new(W)})
    end
end
puts $count
