#include<iostream>
#include<map>
#include<numeric>
#include<cstdio>
#include<iomanip>
#include<algorithm>

using namespace std;

#define REP(i,n) for(int i = 0;i < n;i++)
	
int r,n;
map<int ,map<int ,double> > biuld;

bool judge(double high)
{
	for(int i = -r;i < r;i++)
	{
		double y = biuld[i][i+1] - high;
		if(y < 0 || i*i + y*y < r*r || (i+1)*(i+1) + y*y < r*r)
			return true;
	}
	return false;
	
}

int main()
{
	cout << setprecision(4) << fixed;
	
	while(cin >> r >> n,r)
	{
		biuld.clear();
		double lx,rx,h;
		REP(i,n)
		{
			cin >> lx >> rx >> h;
			for(int j = lx;j < rx;j++)
			{
				biuld[j][j+1] = max(biuld[j][j+1],h);
			}
		}
		
		double ub = -r,hb = 21;
		REP(i,100)
		{
			double mid = (ub+hb)/2;
			if(judge(mid))hb = mid;
			else ub = mid;
		//	cout << ub << ' ' << hb << endl;
		}
		
		cout << ub + (double)r << endl;
		
	}
	
	return 0;
}