#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;


int main() {
	while (1) {

		int R, N; cin >> R >> N;
		if (!R)break;
		vector<int>heights(42,0);
		
		for (int i = 0; i < N; ++i) {
			int l, r, h; cin >> l >> r >> h;
			l += 21; r += 21;
			for (int i = l; i < r; ++i) {
				heights[i] = max(heights[i], h);
			}
		}
		vector<ld>times(41, 99999);
		for (int i = 0; i < 41; ++i) {
			int dx = abs(i - 20);
			if (dx < R) {
				ld dy = R-sqrtl(R*R - dx*dx);
				times[i] = min(heights[i+1],heights[i]) +dy;
			}
		}
		ld ans = *min_element(times.begin(), times.end());
		cout << fixed<<setprecision(5)<<ans << endl;
	}
	return 0;
}