#include <bits/stdc++.h>
using namespace std;
const int MAXSIZE = 101;
bool obj[MAXSIZE][MAXSIZE][MAXSIZE] = {};
tuple<int, int, int> Direction[6] = { {1,0, 0} , {-1, 0,0 } , {0,1,0} , {0,-1,0} , {0,0,1} , {0,0,-1} };
int main() {
int N, M, H, counter = 0;
cin >> N >> M;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
cin >> H;
for (int k = 0; k < H; k++)
{
obj[i][j][k] = true;
counter++;
}
}
}
solution(N, M, counter);
return 0;
}
void solution(int N, int M, int counter)
{
cout << getSurface(N, M, counter);
}
int getSurface(int N, int M, int counter)
{
int result = counter * 6;
int k = 0;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
k = 0;
while (obj[i][j][k])
{
result -= getAdjacent(N, M, i, j, k);
k++;
}
}
}
return result;
}
int getAdjacent(int N, int M, int i , int j ,int k)
{
int nextX, nextY, nextZ, x, y , z, counter;
counter = nextX = nextY = nextZ = 0;
for (auto& dir : Direction)
{
auto& [y, x, z] = dir;
nextY = i + y; nextX = j + x; nextZ = k + z;
if (nextY < 0 || N <= nextY) continue;
if (nextX < 0 || M <= nextX) continue;
if (obj[nextY][nextX][nextZ]) counter++;
}
return counter;
}