input_1
data1 = [int(ii) for ii in input_1.split()]
w = data1[0]
l = data1[1]
g = []
for ii in range(w):
g.append(data1[2+(ii)*l:2+(ii+1)*l])
print(w,l)
print(g)
# w,l=input().split()
# w=int(w)
# l=int(l)
# g=[]
# for ii in range(w):
# tmp=[int(i) for i in input().split()]
# g.append([tmp])
ans=0
if w<5 or l<5:
print(0)
else:
for ii in range(w-4):
for jj in range(l-4):
f=[]
for x in range(ii,ii+5,1):
for y in range(jj,jj+5,1):
tmp=g[x][y]
f.append(tmp)
f=set(f)
if len(f)>=5:
ans=ans+1
print(ans)