#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>

#define MAX_N 20

using namespace std;

int N, R;
int lx[MAX_N], rx[MAX_N], h[MAX_N];
int inf = 100000000;

bool judge(double t){
	for (int x = -R+1; x < R; x++)
	{
		int l = inf, r = inf, m = 0;
		int y;
		for (int i = 0; i < N; i++)
		{
			if(lx[i] == x){
				r = min(h[i], r);
			}else if(rx[i] == x){
				l = min(h[i], l);
			}else if(lx[i] < x && x < rx[i]){
				m = max(h[i], m);
			}
		}
		if(l == inf || r == inf) y = 0;
		else y = min(l, r);
		if(m > y) y = m;
		if(y < (double)sqrt(R*R-x*x)-R+t) return true;
	}
	return false;
}

void solve() {
	double maxT = 21;
	double minT = 0;
	while(maxT - minT > 0.0001){
		double t = (maxT+minT)/2;
		if(judge(t)){// ???????????????
			maxT = t;
		}else{// ????????????
			minT = t;
		}
	}
	printf("%.4lf\n", (maxT+minT)/2);
	return;
}

int main(){
	while(1){
		cin >> R >> N;
		if(R == 0 && N == 0) break;
		for (int i = 0; i < N; i++)
		{
			cin >> lx[i] >> rx[i] >> h[i];
		}
		solve();
	}
	return 0;
}