loop do
    r, n = gets.split.map(&:to_i)
    break if r == 0 && n == 0
    b = n.times.map{gets.split.map(&:to_i)}
    h = Array.new(41,0)
    b.each do |xl,xr,ht|
        (xl+20).upto(xr+19) do |x|
            h[x] = ht
        end
    end
    ans = Float::INFINITY
    (-r+20).upto(r+19) do |c|
        dl = 20 - c
        dr = dl - 1
        ret1 = r - Math.sqrt(r * r - dl * dl) + h[c]
        ans = ret1 if ret1 < ans
        ret2 = r - Math.sqrt(r * r - dr * dr) + h[c]
        ans = ret2 if ret2 < ans
    end
    p ans
end