#include<iostream>
#include<cstring>
using namespace std;
 
int main(){
    int n,m,a,b,x[110][110],y[110][110],sum=0;
    memset(x,0,sizeof(x));
    cin>>m>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>x[i][j];
        }
    }
    memset(y,0,sizeof(y));
	a=100;
	if(m==100){
		for(int i=1;i<=50;i++){
			if(x[2][i]==0){
				b++;
			}
		}
		if(b==50){
			a=10000;
		}
	}
    for(int i=1;i<=m;i++){
        if(x[1][i]==0){
            y[1][i]=1;
            for(int j=1;j<a;j++){
                for(int k=1;k<=n;k++){
                    for(int l=1;l<=m;l++){
                        if(x[k][l]==0 && y[k][l]==1){
                            if(x[k][l-1]==0){
                                y[k][l-1]=1;
                            }
                            if(x[k-1][l]==0){
                                y[k-1][l]=1;
                            }
                            if(k%2==0){
                                if(x[k-1][l-1]==0){
                                    y[k-1][l-1]=1;
                                }
                                if(x[k+1][l-1]==0){
                                    y[k+1][l-1]=1;
                                }
                            }
                            if(x[k][l+1]==0){
                                y[k][l+1]=1;
                            }
                            if(x[k+1][l]==0){
                                y[k+1][l]=1;
                            }
                            if(k%2==1){
                                if(x[k+1][l+1]==0){
                                    y[k+1][l+1]=1;
                                }
                                if(x[k-1][l+1]==0){
                                    y[k-1][l+1]=1;
                                }
                            }
                        }
                    }
                }
                sum=0;
            }
        }
    }
    for(int i=1;i<=m;i++){
        if(x[n][i]==0){
            y[n][i]=1;
            for(int j=1;j<a;j++){
                for(int k=1;k<=n;k++){
                    for(int l=1;l<=m;l++){
                        if(x[k][l]==0 && y[k][l]==1){
                            if(x[k][l-1]==0){
                                y[k][l-1]=1;
                            }
                            if(x[k-1][l]==0){
                                y[k-1][l]=1;
                            }
                            if(k%2==0){
                                if(x[k-1][l-1]==0){
                                    y[k-1][l-1]=1;
                                }
                                if(x[k+1][l-1]==0){
                                    y[k+1][l-1]=1;
                                }
                            }
                            if(x[k][l+1]==0){
                                y[k][l+1]=1;
                            }
                            if(x[k+1][l]==0){
                                y[k+1][l]=1;
                            }
                            if(k%2==1){
                                if(x[k+1][l+1]==0){
                                    y[k+1][l+1]=1;
                                }
                                if(x[k-1][l+1]==0){
                                    y[k-1][l+1]=1;
                                }
                            }
                        }
                    }
                }
                sum=0;
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(x[i][1]==0){
            y[i][1]=1;
            for(int j=1;j<a;j++){
                for(int k=1;k<=n;k++){
                    for(int l=1;l<=m;l++){
                        if(x[k][l]==0 && y[k][l]==1){
                            if(x[k][l-1]==0){
                                y[k][l-1]=1;
                            }
                            if(x[k-1][l]==0){
                                y[k-1][l]=1;
                            }
                            if(k%2==0){
                                if(x[k-1][l-1]==0){
                                    y[k-1][l-1]=1;
                                }
                                if(x[k+1][l-1]==0){
                                    y[k+1][l-1]=1;
                                }
                            }
                            if(x[k][l+1]==0){
                                y[k][l+1]=1;
                            }
                            if(x[k+1][l]==0){
                                y[k+1][l]=1;
                            }
                            if(k%2==1){
                                if(x[k+1][l+1]==0){
                                    y[k+1][l+1]=1;
                                }
                                if(x[k-1][l+1]==0){
                                    y[k-1][l+1]=1;
                                }
                            }
                        }
                    }
                }
                sum=0;
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(x[i][m]==0){
            y[i][m]=1;
            for(int j=1;j<a;j++){
                for(int k=1;k<=n;k++){
                    for(int l=1;l<=m;l++){
                        if(x[k][l]==0 && y[k][l]==1){
                            if(x[k][l-1]==0){
                                y[k][l-1]=1;
                            }
                            if(x[k-1][l]==0){
                                y[k-1][l]=1;
                            }
                            if(k%2==0){
                                if(x[k-1][l-1]==0){
                                    y[k-1][l-1]=1;
                                }
                                if(x[k+1][l-1]==0){
                                    y[k+1][l-1]=1;
                                }
                            }
                            if(x[k][l+1]==0){
                                y[k][l+1]=1;
                            }
                            if(x[k+1][l]==0){
                                y[k+1][l]=1;
                            }
                            if(k%2==1){
                                if(x[k+1][l+1]==0){
                                    y[k+1][l+1]=1;
                                }
                                if(x[k-1][l+1]==0){
                                    y[k-1][l+1]=1;
                                }
                            }
                        }
                    }
                }
                sum=0;
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(y[i][j]!=1){
                x[i][j]=1;
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(x[i][j]==1){
                if(x[i][j-1]==0){
                    sum++;
                }
                if(x[i][j+1]==0){
                    sum++;
                }
                if(x[i-1][j]==0){
                    sum++;
                }
                if(x[i+1][j]==0){
                    sum++;
                }
                if(i%2==0){
                    if(x[i-1][j-1]==0){
                        sum++;
                    }
                    if(x[i+1][j-1]==0){
                        sum++;
                    }
                }
                if(i%2==1){
                    if(x[i-1][j+1]==0){
                        sum++;
                    }
                    if(x[i+1][j+1]==0){
                        sum++;
                    }
                }
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 1268