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