package main

import (
	"fmt"
)

func main() {
	var W, H int
	fmt.Scan(&H, &W)
	s := ""
	m := make([][]int, H)
	for h := 0; h < H; h++ {
		fmt.Scan(&s)
		line := make([]int, W)
		for w := 0; w < W; w++ {
			tmp := s[w : w+1]
			if tmp == "." {
				line[w] = 1
			}
		}
		m[h] = line
	}

	odd := 0
	even := 0
	for h := 0; h < H; h++ {
		for w := 0; w < W; w++ {
			location := m[h][w]
			if location == 0 {
				continue
			}
			road := 0
			if w-1 >= 0 {
				if m[h][w-1] == 1 {
					road++
				}
			}
			if h-1 >= 0 {
				if m[h-1][w] == 1 {
					road++
				}
			}
			if w+1 < W {
				if m[h][w+1] == 1 {
					road++
				}
			}
			if h+1 < H {
				if m[h+1][w] == 1 {
					road++
				}
			}
			// fmt.Println(h, w, road)
			if road >= 1 {
				if road%2 == 0 {
					even++
				} else {
					odd++
				}
			}
		}
	}
	res := even
	if odd >= 2 {
		res += 2
	}
	fmt.Println(res - 1)

}
