

function main(arg) {
	arg = arg.split("\n")
	var tmp = arg[0].split(" ")
	const H = Number(tmp[0])
	const W = Number(tmp[1])

	arg.shift()
	var map = arg

	var histories = []

	var count = 0

	var flag = false

	function dfs(x, y) {
		
		var tests = [
			[y - 1, x],
			[y + 1, x],
			[y, x - 1],
			[y, x + 1],
		]

		for (var n = 0; n < tests.length; n++) {
			var _y = tests[n][0]
			var _x = tests[n][1]

			if (0 <= _x && _x < W && 0 <= _y && _y < H) {
				if (map[_y][_x] !== map[y][x]) {
					var history = _y  + ':' + _x;
					if (histories.indexOf(history) == -1) {
						flag = true
						histories.push(history)
						// console.log("--------" + map[y][x])
						// console.log(histories)
						// console.log("--------" + map[_y][_x])
						dfs(_x, _y)
						histories.pop()
						
					}
				} 
			}
		}
		if (histories.length === 2) {
			count++
		}
	}

	for (var i = 0; i < H; i++) {
		for (var j = 0; j < W; j++) {
			if (map[i][j] === "#") {
				var history = j  + ':' + i;
				histories.push(history)
				dfs(j, i)
				histories.pop()
			}
		}
	}

	console.log(count)

	// counter.sort()
	// for (var i = 0; i < counter.length; i++) {
	// 	console.log(counter[i])
	// }

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));