#include <stdio.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll n,r;
	while(scanf("%lld%lld",&r,&n),r){
		ll aaa[50]={},*a=aaa+25;
		a[-r-1]=a[r]=1e9;
		while(n--){
			ll xl,xr,h;
			scanf("%lld%lld%lld",&xl,&xr,&h);
			rep(i,xl,xr)a[i]=max(a[i],h);
		}
		double ans=1e10;
		//地上に出るまでの時間+高さ
		rep(i,-r,r+1)ans=min(ans,min(a[i-1],a[i])+r-sqrt(r*r-i*i));
		printf("%f\n",ans);
	}
}
