while True:

    R, N = list(map(int, input().split()))

    if not (R | N):

        break

    geta = 20

    buildings = [0] * (geta * 2)

    for _ in range(N):

        xl, xr, h = list(map(int, input().split()))

        for i in range(xl + geta, xr + geta):

            buildings[i] = max(buildings[i], h)



    left, right = 0, 20

    while right - left > 1e-4:

        mid = (left + right) / 2

        flag = True

        for i in range(-R + geta, R + geta):

            if i < geta:

                y = pow(R * R - (i - geta + 1) * (i - geta + 1), 0.5)

                flag &= buildings[i] >= y - R + mid

            else:

                y = pow(R * R - (i - geta) * (i - geta), 0.5)

                flag &= buildings[i] >= y - R + mid

        if flag:

            left = mid

        else:

            right = mid

    print(("{:.20f}".format(left)))
while True:

    R, N = list(map(int, input().split()))

    if not (R | N):

        break

    geta = 20

    buildings = [0] * (geta * 2)

    for _ in range(N):

        xl, xr, h = list(map(int, input().split()))

        for i in range(xl + geta, xr + geta):

            buildings[i] = max(buildings[i], h)



    sun = [0] * (geta * 2)

    for i in range(-R + geta, R + geta):

        if i < geta:

            buildings[i] -= pow(R * R - (i - geta + 1) * (i - geta + 1), 0.5) - R

        else:

            buildings[i] -= pow(R * R - (i - geta) * (i - geta), 0.5) - R





    left, right = 0, 20

    while right - left > 1e-4:

        mid = (left + right) / 2

        flag = True

        for i in range(-R + geta, R + geta):

            if i < geta:

                flag &= buildings[i] >= mid

            else:

                y = pow(R * R - (i - geta) * (i - geta), 0.5)

                flag &= buildings[i] >= mid

        if flag:

            left = mid

        else:

            right = mid

    print(("{:.20f}".format(left)))
while True:
    R, N = list(map(int, input().split()))
    if not (R | N):
        break
    geta = 20
    buildings = [0] * (geta * 2)
    for _ in range(N):
        xl, xr, h = list(map(int, input().split()))
        for i in range(xl + geta, xr + geta):
            buildings[i] = max(buildings[i], h)
    left, right = 0, 20
    while right - left > 1e-4:
        mid = (left + right) / 2
        flag = True
        for i in range(-R + geta, R + geta):
            if i < geta:
                y = pow(R * R - (i - geta + 1) * (i - geta + 1), 0.5)
                flag &= buildings[i] >= y - R + mid
            else:
                y = pow(R * R - (i - geta) * (i - geta), 0.5)
                flag &= buildings[i] >= y - R + mid
        if flag:
            left = mid
        else:
            right = mid
    print(("{:.20f}".format(left)))

while True:
    R, N = list(map(int, input().split()))
    if not (R | N):
        break
    geta = 20
    buildings = [0] * (geta * 2)
    for _ in range(N):
        xl, xr, h = list(map(int, input().split()))
        for i in range(xl + geta, xr + geta):
            buildings[i] = max(buildings[i], h)
    sun = [0] * (geta * 2)
    for i in range(-R + geta, R + geta):
        if i < geta:
            buildings[i] -= pow(R * R - (i - geta + 1) * (i - geta + 1), 0.5) - R
        else:
            buildings[i] -= pow(R * R - (i - geta) * (i - geta), 0.5) - R
    left, right = 0, 20
    while right - left > 1e-4:
        mid = (left + right) / 2
        flag = True
        for i in range(-R + geta, R + geta):
            if i < geta:
                flag &= buildings[i] >= mid
            else:
                y = pow(R * R - (i - geta) * (i - geta), 0.5)
                flag &= buildings[i] >= mid
        if flag:
            left = mid
        else:
            right = mid
    print(("{:.20f}".format(left)))

+    sun = [0] * (geta * 2) +    for i in range(-R + geta, R + geta): +        if i < geta: +            buildings[i] -= pow(R * R - (i - geta + 1) * (i - geta + 1), 0.5) - R +        else: +            buildings[i] -= pow(R * R - (i - geta) * (i - geta), 0.5) - R -                y = pow(R * R - (i - geta + 1) * (i - geta + 1), 0.5) -                flag &= buildings[i] >= y - R + mid +                flag &= buildings[i] >= mid -                flag &= buildings[i] >= y - R + mid +                flag &= buildings[i] >= mid