class Ufo
  def initialize(x, y, r, v)
    @dist = Math.sqrt(x ** 2 + y ** 2)
    @x = x
    @y = y
    @r = r
    @v = v
    @ex = x / @dist
    @ey = y / @dist
    @vx = -v * @ex
    @vy = -v * @ey
  end
  attr_reader :x, :y, :r, :dist, :ex, :ey
  
  def move
    @dist -= @v
    @x += @vx
    @y += @vy
  end
end

loop do
  radius, n = gets.split.map(&:to_i)
  break if (radius + n).zero?
  
  ufos = n.times.map {Ufo.new(*gets.split.map(&:to_i))}
  count = 0
  
  loop do
    ufos.each(&:move)
    ufos.sort_by! {|u| u.dist}
    
    ufos1 = ufos.select {|u| u.dist <= radius}
    count += ufos1.size
    ufos -= ufos1
    break if ufos.size.zero?
    
    min = ufos.shift
      
    ufos = ufos.reject do |u|
      r = (min.y * u.x - min.x * u.y).abs / min.dist
      r < u.r &&
          u.dist * (min.ex * u.ex + min.ey * u.ey) +
             Math.sqrt(u.r ** 2 - r ** 2) > radius
    end
    break if ufos.size.zero?
  end
  
  puts count
end

