import java.lang.Math.*
fun main(args: Array<String>?): Unit {
    while(true){
        val (r, n) = readLine()!!.trim().split(' ').map(String::toInt)
        if (r == 0 && n == 0) return
        val height = IntArray(41){0}
        repeat(n){
            val (xl, xr, h) = readLine()!!.trim().split(' ').map(String::toInt)
            for (x in xl until xr) {
                height[x + 20] = max(h, height[x + 20])
            }
        }
        var last = Double.MAX_VALUE
        for (x in 0 .. 20) last = min(last, lastTime(x, height[x + 20], r))
        for (x in -20 until 0) last = min(last, lastTime(abs(x + 1), height[x + 20], r))
        println("%.10f".format(last))
    }
}

fun lastTime(distance: Int, height: Int, radius: Int): Double {
    return if (radius <= distance) Double.MAX_VALUE else radius - (sqrt(radius * radius * 1.0 - distance * distance) - height)
}
