#include <stdio.h>
#include <math.h>
#define X_MAX 20
#define H_MAX 20

int arr[2 * H_MAX];

int* heights = arr + H_MAX;
int r;

int check(double time)
{
    int x;

    for(x = -r; x < 0; x++)
        if(heights[x] < sqrt(r * r - (x + 1) * (x + 1)) - r + time)
            return 0;

    for(x = 0; x < r; x++)
        if(heights[x] < sqrt(r * r - x * x) - r + time)
            return 0;

    return 1;
}

int main(void)
{
    int n, xl, xr, h;
    double upper, lower, mean;

    while(scanf("%d%d", &r, &n), r + n)
    {
        for(xl = -X_MAX; xl < X_MAX; xl++)
            heights[xl] = 0;

        while(n--)
        {
            scanf("%d%d%d", &xl, &xr, &h);
            for(; xl < xr; xl++)
                if(heights[xl] < h) heights[xl] = h;
        }

        upper = H_MAX;
        lower = 0;
        mean = (upper + lower) / 2;
        while(upper - lower > 0.001)
        {
            if(check(mean)) lower = mean;
            else upper = mean;
            mean = (upper + lower) / 2;
        }

        printf("%lf\n", mean);
    }

    return 0;
}