R,C=map(int,input().split())
L=[]
c=0
for _ in range(R):
L.append([int(x) for x in input().split()])
for i in range(R):
for j in range(C):
flag=True
for iz in range(max(0,i-1),min(R,i+2)):
for jz in range(max(0,j-1),min(C,j+2)):
if i==iz and j==jz:
continue
if L[i][j]==L[iz][jz]:
flag=False
break
if not flag:
break
if flag:
c+=1
print(c)