def f c,i,j
$m[i][j]=?a
[[i,j+1],[i,j-1],[i+1,j],[i-1,j]].map{|a,b|$m[a][b]==c&&f(c,a,b)}end
while(h,w=gets.split.map &:to_i)[0]>0
$m=(1..h).map{gets+?a}+[?a*w]
n=0
h.times{|i|w.times{|j|(c=$m[i][j])<?a&&(n+=1)&&f(c,i,j)}}
p n
end