### constant

DELTA = 1e-12
DIV = 5000
PIDIV = Math::PI / DIV

### subroutines

def visible?(t)
  y0 = t - $r
  for d in (0..DIV)
    th = PIDIV * d
    x = $r * Math.cos(th)
    y = $r * Math.sin(th) + y0
    next if y <= 0.0

    covered = false
    $rects.each do |x0, x1, h|
      if x >= x0 && x <= x1 && y <= h
        covered = true
        break
      end
    end
    return true if ! covered
  end
  false
end

### main

loop do
  $r, $n = gets.split.map(&:to_i)
  break if ($r | $n) == 0

  $rects = $n.times.map{gets.split.map(&:to_i)}
  #p $rects

  t0 = 0.0
  t1 = 20.0
  while (t1 - t0 > DELTA)
    t = (t0 + t1) / 2
    if visible?(t)
      t1 = t
    else
      t0 = t
    end
  end
  puts t0
end