### constant

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

### main

loop do
  w, h = gets.split.map(&:to_i)
  break if (w | h) == 0

  flds = h.times.map{gets.split.map(&:to_i)}
  #p flds

  count = 0

  for y0 in (0...h)
    for x0 in (0...w)
      if flds[y0][x0] > 0
        count += 1
        flds[y0][x0] = -1
        q = [[x0, y0]]

        while ! q.empty?
          xq, yq = q.shift

          DXYS.each do |dx, dy|
            x = xq + dx
            y = yq + dy
            if x >= 0 && x < w && y >= 0 && y < h && flds[y][x] > 0
              flds[y][x] = -1
              q << [x, y]
            end
          end
        end
      end
    end
  end

  puts count
end