#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) loop(i,0,n)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<pii> vp;
typedef vector<vi> vvi;
typedef vector<string> vs;
Def inf = sizeof(Def) == sizeof(ll) ? 2e18:1e9+10;
int main(){
	int n,R;
	while(cin>>R>>n,R){
		vi in(60);
		rep(i,n){
			int a,b,c;
			cin>>a>>b>>c;
			a+=30;b+=30;
			loop(j,a,b)in[j]=max(in[j],c);
		}
		double l=0,r=21;
	//	rep(i,60)cout<<" "<<in[i];cout<<endl;
		while(r-l>0.0001){
			double h=(l+r)/2;
			bool H=true;
			rep(q,50){
				int t=q-25;
				if(abs(t)>R)continue;
				int hi=min(in[t+29],in[t+30]);
				if(t==R)hi=in[t+29];
				else if(-t==R)hi=in[t+30];
				if(h-R>hi)H=false;
				if(R*R>t*t+(hi-(h-R))*(hi-(h-R)))H=false;
			}
//			cout<<shosu(4)<<h<<" "<<H<<endl;
			if(H)l=h;
			else r=h;
		}
		cout<<shosu(9)<<l<<endl;
	}
}





