### constant

DXYS = [
  [[1, 0], [1, -1], [ 0, -1], [-1, 0], [ 0, 1], [1, 1]],
  [[1, 0], [0, -1], [-1, -1], [-1, 0], [-1, 1], [0, 1]]
]

### main

w, h = gets.strip.split(' ').map{|s| s.to_i}

brds = h.times.map{gets.strip.split(' ').map{|s| s.to_i}}

q = []
for y in (0...h)
  if brds[y][0] == 0
    brds[y][0] = -1
    q << [0, y]
  end
  if brds[y][w - 1] == 0
    brds[y][w - 1] = -1
    q << [w - 1, y]
  end
end
for x in (0...w)
  if brds[0][x] == 0
    brds[0][x] = -1
    q << [x, 0]
  end
  if brds[h - 1][x] == 0
    brds[h - 1][x] = -1
    q << [x, h - 1]
  end
end

while ! q.empty?
  x, y = q.pop
  dxys = DXYS[y & 1]
  for i in (0...6)
    x0 = x + dxys[i][0]
    y0 = y + dxys[i][1]
    if x0 >= 0 && x0 < w && y0 >= 0 && y0 < h && brds[y0][x0] == 0
      brds[y0][x0] = -1
      q << [x0, y0]
    end
  end
end

for y in (0...h)
  for x in (0...w)
    brds[y][x] = 1 if brds[y][x] == 0
  end
end

count = 0

for y in (0...h)
  dxys = DXYS[y & 1]
  for x in (0...w)
    next if brds[y][x] != 1

    for i in (0...6)
      x0 = x + dxys[i][0]
      y0 = y + dxys[i][1]

      if x0 < 0 || x0 >= w || y0 < 0 || y0 >= h || brds[y0][x0] == -1
        count += 1
      end
    end
  end
end

puts count