None, Wall, Visited = (0...3).to_a
Y, X = 0, 1
Even, Odd = 0, 1
NextPoint = [
  [[0,-1], [0,1], [-1,-1], [-1,0], [1,-1], [1,0]],
  [[0,-1], [0,1], [-1,0], [-1,1], [1,0], [1,1]],
]

def bfs!(map, y, x)
  q = Array.new.push([y,x])
  count = 0
  until q.empty? do
    y, x = q.pop
    next if map[y][x] == Visited
    map[y][x] = Visited
    parity = (y&1 == 0) ? Even : Odd
    NextPoint[parity].each do |d|
      nextY, nextX = y+d[Y], x+d[X]
      next if nextY < 0 || map.size <= nextY
      next if nextX < 0 || map[nextY].size <= nextX
      case map[nextY][nextX]
        when Wall
          count += 1
        when None
          q.push([nextY, nextX])
      end
    end
  end
  count
end

w, h = gets.split.map(&:to_i)
map = Array.new
map.push((0...w+2).collect{None})
map.push(*(0...h).collect{[None, *gets.split.map(&:to_i), None]})
map.push((0...w+2).collect{None})
p bfs!(map, 0, 0)