if __name__ == "__main__": N, M =map(int, input().split()) loc = [] area = 0 for _ in range(N): tmp = list(map(int, input().split())) area += sum(tmp) loc.append(tmp) area *= 6 sub = 0 for i in range(N): for j in range(M): if loc[i][j] > 1: sub += (loc[i][j]-1)*2 if j > 0: sub += min(loc[i][j-1], loc[i][j])*2 if i > 0: sub += min(loc[i-1][j], loc[i][j])*2 print(area - sub)