#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<cmath>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)
#define pb push_back

const int INF  = 1000000007;

int r,n;
map<int,int> bill;
bool input(){
	cin>>r>>n;
	if(r==0 && n==0)return false;
	
	bill.clear();
	reps(i,-20,20+1){
		bill[i] = 0;
	}
	rep(i,n){
		int a,b,c;
		cin>>a>>b>>c;
		
		reps(i,a,b)bill[i]=max(bill[i],c);
	}
	
	return true;
}


double check(int x, int h){
	if(abs(x)>=r)return INF;
	
	double t = h + r - sqrt(r*r-x*x);
	return t;
}

void solve(){
	
	double ans = INF;
	for(map<int,int>::iterator it = bill.begin(); it!=bill.end(); it++){
		int x = it->first;
		int h = it->second;
		
		ans = min(ans, check(x,h));
		ans = min(ans, check(x+1,h));
	}
	
	printf("%.9lf\n",ans);
}

int main(){
	
	while(input())solve();
}