#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	double r;
	while(cin>>r>>n,r||n){
		double h[50]={0};
		rep(i,n){
			int a,b;
			double c;
			cin>>a>>b>>c;
			a+=25;b+=25;
			for(int i=a;i<b;i++)h[i]=max(h[i],c);
		}
		//loop(i,20,30)cout<<" "<<h[i];
		//cout<<endl;
		double t=0;
		while(1){
			t+=0.0001;
			bool ans=true;
			rep(i,49){
				if((double)(i-25)*(i-25)+(r+h[i]-t)*(r+h[i]-t)<r*r){
					ans=false;
					break;
				}
				if((double)(i-24)*(i-24)+(r+h[i]-t)*(r+h[i]-t)<r*r){
					ans=false;
					break;
				}
			}
			if(!ans)break;
		}
		cout<<t-0.0001<<endl;
	}
	
}