import java.util.*

fun main(args: Array<String>?): Unit {
    val (width, height) = readLine()!!.trim().split(' ').map(String::toInt)
    val state = Array(height){ readLine()!!.trim().split(' ').map(String::toInt).toIntArray()}
    val queue = LinkedList<HexPoint>()
    for (h in 0 until height) {
        if (state[h][0] == 0) queue.push(HexPoint(0, h))
        if (state[h].last() == 0) queue.push(HexPoint(state[h].lastIndex, h))
    }
    for (w in 0 until width){
        if (state[0][w] == 0) queue.push(HexPoint(w, 0))
        if (state.last()[w] == 0) queue.push(HexPoint(w, state.lastIndex))
    }
    for (hp in queue) state[hp.y][hp.x] = 2
    while(queue.isNotEmpty()) {
        val current = queue.pop()
        for (next in current.neighbors()) if (next.x in 0 until width && next.y in 0 until height && state[next.y][next.x] == 0){
            state[next.y][next.x] = 2
            queue.push(next)
        }
    }
    println(
            (0 until width).sumBy{ x -> (0 until height).filter{y -> state[y][x] == 1}.sumBy { y -> HexPoint(x, y).neighbors().count{ hp -> hp.x !in 0 until width || hp.y !in 0 until height || state[hp.y][hp.x] == 2 } }}
    )

}
data class HexPoint(val x: Int, val y: Int) {
    fun neighbors(): List<HexPoint> = when(y % 2 == 0){
        true -> listOf(HexPoint(x, y - 1), HexPoint(x + 1, y - 1), HexPoint(x - 1, y), HexPoint(x + 1, y), HexPoint(x, y + 1), HexPoint(x + 1, y + 1))
        false -> listOf(HexPoint(x - 1, y - 1), HexPoint(x, y - 1), HexPoint(x - 1, y), HexPoint(x + 1, y), HexPoint(x - 1, y + 1), HexPoint(x, y + 1))
    }
}
