var r;
var n;
var x = [];
var e = [];

function fill(a, b, h){
	a += 20;
	b += 20;
	x[a][0] += 1;
	x[a][h] -= 1;
	x[b][0] -= 1;
	x[b][h] += 1;
}

function integrate(){
	rep(40, function(i){
		rep(19, function(j){
			x[i][j + 1] += x[i][j];
		});
	});
	rep(39, function(i){
		rep(20, function(j){
			x[i + 1][j] += x[i][j];
		});
	});
}

function access(i, j){
	return x[i + 20][j];
}

function calc_edge(){
	e[0] = Infinity;
	rep(20, function(i){
		var a = 0;
		rep(20, function(j){
			if(access(-j - 1, i)){
				++a;
			}
			else{
				return false;
			}
		});

		var b = 0;
		rep(20, function(j){
			if(access(j, i)){
				++b;
			}
			else{
				return false;
			}
		});

		var c = Math.min(a, b);
		e[i + 1] = c;
		e[i] = Math.min(c, e[i]);
	});
}

function judge(h){
	var b = true;
	rep(21, function(i){
		var dh = Math.abs(i - h);
		var lim = r * r - dh * dh;
		if(lim < 0){
			return;
		}
		lim = Math.sqrt(lim);
		if(lim > e[i]){
			b = false;
			return false;
		}
	});
	return b;
}

function main(){
	while(r = scan()){
		rep(41, function(i){
			x[i] = [];
			rep(21, function(j){
				x[i][j] = 0;
			});
		});

		n = scan();
		rep(n, function(){
			var a = scan();
			var b = scan();
			var h = scan();
			fill(a, b, h);
		});
		integrate();

		calc_edge();
		
		var a = 0, b = 20;
		while(b - a > 1e-4){
			var c = (a + b) / 2;
			if(judge(c - r)){
				a = c;
			}
			else{
				b = c;
			}
		}
		print(a);
	}
}

function rep(a, b, c, u){
	if(c === u){
		c = b;
		b = a;
		a = 0;
	}
	for(var i = a; i < b; ++i){
		if(c(i) === false){
			break;
		}
	}
}

var input = '';

function scan(){
	return +input.pop();
}
function scan_string(){
	return input.pop();
} 
function print(val){
	console.log(val);
}
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.trim().split(/\s+/).reverse();
	main();
});