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 dfs!(map, y, x)
  map[y][x] = Visited
  count = 0
  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
        count += dfs!(map, nextY, nextX)
    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 dfs!(map, 0, 0)