import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new Scanner(System.in)
    while (true) {
      val R = scanner.nextInt()
      val N = scanner.nextInt()
      if (R == 0 && N == 0) {
        return
      }
      val in = List.fill(N)(scanner.nextInt, scanner.nextInt, scanner.nextInt)
      var map = scala.collection.mutable.ArrayBuffer.fill(R * 2)(0)
      in.foreach {
        case (xl, xr, h) =>
          (xl until xr)
            .map(_ + R)
            .filter(_ >= 0)
            .filter(_ < map.length)
            .foreach(i => map(i) = Math.max(map(i), h))
      }
      val result = map.zipWithIndex.map {
        case (h, index) => calc(index, h, R)
      }.min
      println(result)
    }
  }

  def calc(index: Int, h: Int, R: Int): Double = {
    h + R - Math.sqrt(Math.pow(R, 2) - Math.pow(getRFromIndex(index, R), 2))
  }

  def getRFromIndex(index: Int, R: Int): Double = {
    R - index match {
      case r if r <= 0 => -r
      case r => r - 1
    }
  }
}