n_input=int(input())
m_input=int(input())
str_mn=input()
total_list=[]
sum=0
matrixA=[]#状态矩阵
for i in range(n_input):
    matrixA.append([False]*m_input)
mn_list=str_mn.split(' ')
for i in range(n_input):
     total_list.append(mn_list[i*m_input:(i+1)*m_input])
# print(total_list)
for n_i in range(len(total_list)-1):
    for m_j in range(len(total_list[n_i])-1):
        if matrixA[n_i][m_j]!=True:
            print(total_list[n_i][m_j])
            if int(total_list[n_i][m_j])==1 and int(total_list[n_i][m_j+1])==1 and int(total_list[n_i+1][m_j])==1 and int(total_list[n_i+1][m_j+1])==1:
                sum+=1
                matrixA[n_i][m_j]=True
                matrixA[n_i][m_j+1]=True
                matrixA[n_i+1][m_j]=True 
                matrixA[n_i+1][m_j+1]=True
        else:
            continue
print(sum)