#include "bits/stdc++.h"

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)

const double EPS = 1e-14;

struct building {
	double l, r, h;
};

void solve() {
	double r;int N; cin >> r >> N;
	if (r==0&&N == 0)exit(0);
	vector<building>v;
	REP(i, N) {
		double L, R, H; cin >> L >> R >> H;
		v.push_back({ L,R,H });
	}
	double ok = 0, ng = 1000;
	REP(_, 50) {

		double mid = (ok + ng) / 2;
		/*cout << mid << endl;*/
		double d = 2 * r / 200000;
		REP(c, 200001) {
			double x = -r + d * c;
			//cout << "x:" << x << endl;
			if (r*r - x * x < 0 + EPS)continue;
			double y = sqrt(r*r - x * x)-r+mid;
			if (y < EPS)continue;
			//cout << "y:" << y << endl;
			bool good = false;

			REP(i, N) {
				if (v[i].l < x + EPS && x - EPS < v[i].r&&y - EPS < v[i].h) {
					good = true;
					break;
				}
			}
			if (!good) {
				ng = mid;
				goto END;
			}
		}
		ok = mid;
	END:;
	}
	printf("%.3lf\n",ok);
}

signed main() {
	while (true)solve();
}
