include Math

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

    shadow = Hash.new(0)
    (1..n).each do
        xl, xr, h = gets.split.map(&:to_i)
        (xl..xr-1).each do |x|
            shadow[x] = h if h > shadow[x]
        end
    end

    t_min = Float::INFINITY

    (-r+1..0).each do |x|
        h = shadow[x-1]
        t = h + r - sqrt(r*r-x*x)
        t_min = t if t < t_min
    end

    (1..r-1).each do |x|
        h = shadow[x]
        t = h + r - sqrt(r*r-x*x)
        t_min = t if t < t_min
    end

    p t_min
end