#include <bits/stdc++.h>
using namespace std;

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF = 1<<29;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[2][6] = {{0,1,0,-1,-1,1},{0,1,0,-1,-1,1}};
constexpr int dj[2][6] = {{1,0,-1,0,-1,-1},{1,0,-1,0,1,1}};


int main(){
    int w, h;
    cin >> w >> h;
    vector<vector<int> > a(h+2,vector<int>(w+2)), outside(h+2,vector<int>(w+2));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i+1][j+1];
        }
    }
    queue<P> que;
    que.push(P(0,0));
    outside[0][0] = true;
    while(!que.empty()){
        P p = que.front();
        que.pop();
        int i = p.first, j = p.second;
        for(int k=0;k<6;k++){
            int ni = i+di[i&1][k], nj = j+dj[i&1][k];
            if(ni < 0 || ni > h+1) continue;
            if(nj < 0 || nj > w+1) continue;
            if(outside[ni][nj] || a[ni][nj]) continue;
            que.push(P(ni,nj));
            outside[ni][nj] = true;
        }
    }
    int ans = 0;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(a[i][j]){
                for(int k=0;k<6;k++){
                    int ni = i+di[i&1][k], nj = j+dj[i&1][k];
                    if(outside[ni][nj]) ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


