#include "bits/stdc++.h"
using namespace std;
//#define int long long
#define REP(i, s, n) for (signed i = (s); i < signed(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

signed main() {
	int r, n;
	while (cin >> r >> n && r) {
		V height(r * 2);
		rep(i, n) {
			int lx, rx, h; cin >> lx >> rx >> h;
			lx += r;
			rx += r;
			REP(i, max(0, lx), min(r * 2, rx)) {
				height[i] = max(height[i], h);
			}
		}

		double ans = 1 << 27;
		rep(x, r * 2) {
			int h = height[x];
			double a = sqrt(r * r - pow(abs(r - x) - (r - x > 0), 2));
			double sun = (double)(h + r) - a;
			ans = min(ans, sun);
		}
		printf("%.8f\n", ans);
	}
}