h,w=map(int,input().split()) s=[list(input())for i in range(h)] t=[[0]*w for i in range(h)] for i in range(h): for j in range(w): if t[i][j]:continue Q=[(i,j)] Q2=[(i,j)] di=[1,0,-1,0] dj=[0,1,0,-1] t[i][j]=1 while len(Q): pi,pj=Q.pop() for k in range(4): ni=pi+di[k] nj=pj+dj[k] if 0<=ni