def f(w,h,x,y,map1)
map1[y][x]="#"
dfs=[]
dfs<<[y,x]
while dfs.size>0
y,x=dfs.pop
[[1,0],[0,-1],[-1,0],[0,1]].each{|dx,dy|
x2=x+dx
y2=y+dy
next if x2<0 || w<=x2 || y2<0 || h<=y2
next if map1[y2][x2]=="#"
map1[y2][x2]="#"
dfs<<[y2,x2]
}
end
end
h,w=gets.split(" ").map{|e| e.to_i}
map1=[]
h.times{
map1<<gets.chomp
}
[0,h-1].each{|y|
w.times{|x|
f(w,h,x,y,map1) if map1[y][x]=="."
}
}
[0,w-1].each{|x|
h.times{|y|
f(w,h,x,y,map1) if map1[y][x]=="."
}
}
ans=0
h.times{|y|
w.times{|x|
if map1[y][x]=="." then
f(w,h,x,y,map1)
ans+=1
end
}
}
puts ans
ZGVmIGYodyxoLHgseSxtYXAxKQoJbWFwMVt5XVt4XT0iIyIKCWRmcz1bXQoJZGZzPDxbeSx4XQoJd2hpbGUgZGZzLnNpemU+MAoJCXkseD1kZnMucG9wCgkJW1sxLDBdLFswLC0xXSxbLTEsMF0sWzAsMV1dLmVhY2h7fGR4LGR5fAoJCQl4Mj14K2R4CgkJCXkyPXkrZHkKCQkJbmV4dCBpZiB4MjwwIHx8IHc8PXgyIHx8IHkyPDAgfHwgaDw9eTIKCQkJbmV4dCBpZiBtYXAxW3kyXVt4Ml09PSIjIgoJCQltYXAxW3kyXVt4Ml09IiMiCgkJCWRmczw8W3kyLHgyXQoJCX0KCWVuZAplbmQKCmgsdz1nZXRzLnNwbGl0KCIgIikubWFwe3xlfCBlLnRvX2l9Cm1hcDE9W10KaC50aW1lc3sKCW1hcDE8PGdldHMuY2hvbXAKfQpbMCxoLTFdLmVhY2h7fHl8Cgl3LnRpbWVze3x4fAoJCWYodyxoLHgseSxtYXAxKSBpZiBtYXAxW3ldW3hdPT0iLiIKCX0KfQpbMCx3LTFdLmVhY2h7fHh8CgloLnRpbWVze3x5fAoJCWYodyxoLHgseSxtYXAxKSBpZiBtYXAxW3ldW3hdPT0iLiIKCX0KfQphbnM9MApoLnRpbWVze3x5fAoJdy50aW1lc3t8eHwKCQlpZiBtYXAxW3ldW3hdPT0iLiIgdGhlbgoJCQlmKHcsaCx4LHksbWFwMSkKCQkJYW5zKz0xCgkJZW5kCgl9Cn0KcHV0cyBhbnM=