#include<stdio.h>
#include<math.h>

int main() {

	int n;
	double r,h;
	double x_l,x_r;
	int i,j;
	double b[41];
	double t;
	double x,y;

	for(;;) {
		scanf("%lf %d",&r,&n);
		if(r==0&&n==0)
			break;

		for(i=0;i<41;i++)
			b[i]=0;

		//??????????????????????´?
		for(i=0;i<n;i++) {
			scanf("%lf %lf %lf",&x_l,&x_r,&h);
			for(j=x_l+20;j<x_r+20;j++) {
				if(b[j]<h)
					b[j]=h;
			}
		}

		//????????????????????????????????§???????????´????????????????????????????¨????
		t=100;
		for(j=(-r+20)+1;j<=(r+20)-1;j++) {
			x = j-20;
			if(b[j-1]<=b[j])
				y=b[j-1];
			else
				y=b[j];

			if(t>y+r-sqrt(r*r-x*x))
				t=y+r-sqrt(r*r-x*x);

		}
		printf("%f\n",t);
	}
	return 0;
}