$d = [[[-1, -1], [0, -1], [1, -1], [1, 0], [0, 1], [-1, 0]],
      [ [-1, 0], [0, -1],  [1, 0], [1, 1], [0, 1], [-1, 1]]]
     
def bfs(fld, w, h)
  (1..h).each do |i|
    (1..w).each do |j|
      if !fld[i][j]
        flag = true
        v = Array.new(h+2){Array.new(w+2,false)}
        arr = []
        arr << [i, j]
        until arr.empty?
          y, x = arr.shift
          v[y][x] = true
          if y <= 0 || y > h || x <= 0 || x > w
            flag = false
            break
          end
          $d[y%2].each do |dy, dx|
            if !fld[dy+y][dx+x] && !v[dy+y][dx+x] && !arr.include?([dy+y, dx+x]) then arr << [dy+y, dx+x]
            end
          end
        end
        if flag
          h.times do |k|
            w.times do |m|
              fld[k][m] = true if v[k][m]
            end
          end
        end
      end
    end
  end
  fld
end

w, h = gets.split.map(&:to_i)
fld = Array.new(h+2)
(1..h).each{ |i| fld[i] = gets.split(" ") }
(1..h).map{ |i| (0...w).map{ |j| fld[i][j] = fld[i][j] == "1" ? true : false } }
fld[1,h].each{ |arr| arr.unshift(false); arr << false }
fld[0] = [false]*(w+2); fld[h+1] = [false]*(w+2)
fld = bfs(fld, w, h)
sum = 0
(1..h).each do |i|
  (1..w).each do |j|
    if fld[i][j]
      $d[i%2].each do |y, x|
        sum += 1 if !fld[i+y][j+x]
      end
    end
  end
end
p sum