r=->i{P[i]?r[P[i]]:i};m=->i,j{B[i=r[i]]<B[j=r[j]]?m[j,i]:i!=j&&(P[j]=i;B[i]+=B[j];A[i]+=A[j])};eval"H,V="+gets.split*?,;S=$<.map(&:chop)*'';P=[];B=[];A=[];(H*V).times{|g|A[g]=1-B[g]=?.<=>c=S[g];g<V||c!=S[g-V]&&m[g,g-V];g%V>0&&c!=S[g-1]&&m[g,g-1]};a=0;(H*V).times{|g|P[g]||a+=A[g]*B[g]};p a