#include <algorithm>
// #define NDEBUG
#include <cassert>
#include <cctype>
#include <climits>
#define _USE_MATH_DEFINES
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

namespace geo
{
	using namespace std;

	typedef double Double;

	const Double PI = M_PI; // 3.14159265358979323846
	Double EPS = 1e-08;
	Double INF = 1e+12;

	enum {
		CCW = 1, CW = -1, CAB = 2, ABC = -2, ACB = 0,
	};

	typedef complex<Double> P;
	struct L : public vector<P> {
		L ( const P &a, const P &b ) {
			push_back(a); push_back(b);
		}
	};
	typedef vector<P> G;
	struct C {
		P p; Double r;
		C ( const P &ip, Double ir ) : p(ip), r(ir) {}
	};

	namespace comp {
		bool operator < ( const P &a, const P &b ) {
			return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
		}
		bool comp_x ( const P &a, const P &b ) {
			return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
		}
	}

	Double cross ( const P &a, const P &b ) {
		return imag(conj(a) * b);
	}

	Double dot ( const P &a, const P &b ) {
		return real(conj(a) * b);
	}

	bool intersectSP ( const L &s, const P &p ) {
		// triangle inequality
		return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < EPS;
		// parallel && signed dot
		// return cross(s[0] - p, s[1] - p) == 0 && dot(s[0] - p, s[1] - p) <= 0;
	}

	P projection ( const L &l, const P &p ) {
		Double t = dot(p - l[0], l[1] - l[0]) / norm(l[1] - l[0]);
		return l[0] + t * (l[1] - l[0]);
	}

	Double distanceSP ( const L &s, const P &p ) {
		const P r = projection(s, p);
		if (intersectSP(s, r)) { return abs(r - p); }
		return min(abs(s[0] - p), abs(s[1] - p));
	}
}

const int BASE_X = 25;
const int RANGE_H = 25;

bool C ( geo::Double r, geo::Double t, const geo::G& g )
{
	for ( int i = 0; i < g.size() - 1; ++i ) {
		if ( r > distanceSP( geo::L( g[i], g[i + 1] ), geo::P( 0, t - r ) ) ) {
			return false;
		}
	}
	for ( int i = 0; i < g.size() - 1; i += 2 ) {
		geo::P pa = g[i], pb = g[i + 1];
		if ( pa.real() <= 0 && 0 < pb.real() && pa.imag() <= t - r ) {
			return false;
		}
	}
	return true;
}

int main ( void )
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );
	cout << setprecision( 9 );
	cout << setiosflags( ios::fixed );

	int r, n, minx = 1 << 29, maxx = -minx;

	while ( cin >> r >> n, r | n ) {
		VVI m( RANGE_H, VI( BASE_X * 2, 0 ) );
		for ( int i = 0; i < n; ++i ) {
			int xl, xr, h;
			cin >> xl >> xr >> h;

			minx = min( minx, xl );
			maxx = max( maxx, xr );

			for ( int y = 0; y <= h; ++y ) {
				for ( int x = xl; x < xr; ++x ) {
					m[y][BASE_X + x] = 1;
				}
			}
		}

		m[0] = VI( BASE_X * 2, 1 );

		geo::G g;

		g.push_back( geo::P( -( 1 << 29 ), 0 ) );

		int tx = 0, ty = 0, state = 1;

		do {
			switch ( state ) {
			case 1:
				for ( ; tx < BASE_X * 2 && !m[ty + 1][tx]; ++tx );
				if ( tx >= BASE_X * 2 ) { state = 0; }
				else {
					state = 2;
					g.push_back( geo::P( tx - BASE_X, ty ) );
				}
				break;
			case 2:
				for ( ; m[ty + 1][tx]; ++ty );
				state = 3;
				g.push_back( geo::P( tx - BASE_X, ty ) );
				break;
			case 3:
				for ( ; tx + 1 < BASE_X * 2 && m[ty][tx + 1] && !m[ty + 1][tx]; ++tx );
				if ( tx + 1 >= BASE_X * 2 ) { state = 0; }
				else if ( !m[ty][tx + 1] ) {
					state = 4;
					g.push_back( geo::P( tx + 1 - BASE_X, ty ) );
				}
				else if ( m[ty + 1][tx] ) {
					state = 2;
					g.push_back( geo::P( tx - BASE_X, ty ) );
				}
				break;
			case 4:
				for ( ; !m[ty][tx + 1]; --ty );
				state = 3;
				g.push_back( geo::P( tx + 1 - BASE_X, ty ) );
				++tx;
				break;
			}

		} while ( state );

		g.push_back( geo::P( +( 1 << 29 ), 0 ) );

		geo::Double low = 0, high = 21;
		for ( int i = 0; i < 100; ++i ) {
			geo::Double mid = ( low + high ) / 2.0;
			if ( C( r, mid, g ) ) {
				low = mid;
			}
			else {
				high = mid;
			}
		}

		cout << low << endl;
	}

	return 0;
}

Measured memory_bytes: 1324