def move_ufo(ufo) # x,y,dを更新
  x,y,v = ufo[0],ufo[1],ufo[3]
  c = Math.sqrt(x*x + y*y)
  return ufo if c == 0

  cos = x / c
  sin = y / c
  if v < c
    x -= v * cos
    y -= v * sin
  else
    x,y = 0,0
  end

  d = Math.sqrt(x*x + y*y)

  return [x,y,ufo[2],v,d]
end

def graze?(a,b,ufo) # レーザーの当たり判定
  x,y = ufo[0],ufo[1]
  d = (b*x - a*y).abs / Math.sqrt(a*a + b*b)
  return d <= ufo[2]
end

loop do
  _r, n = gets.split(" ").map(&:to_i)
  break if _r == 0
  ufos = [] # x,y,r,v,d
  0.upto(n-1) {|i| ufos[i] = gets.split(" ").map(&:to_f) << 0}


  cnt = 0
  while !ufos.empty?

    ufos.map! {|ufo| move_ufo(ufo)}
    ufos.sort! {|ufo_i,ufo_j| ufo_i[4] <=> ufo_j[4]}

    while ufos[0][4] <= _r # もっとも近いufoがレーザー半径内に入っていたら
      cnt += 1
      ufos.shift
    end
    break if ufos.empty?

    ufo = ufos.shift
    x,y = ufo[0],ufo[1]
    0.upto(ufos.length - 1) do |i|
      break ufos[i].nil?
      if graze?(x,y,ufos[i])
        ufos.slice!(i)
        redo
      end
    end

  end

  puts cnt
end