// Aizu 1194: Vampire
// 2017.9.14 bal4u@uu

#include <stdio.h>
#include <string.h>
#include <math.h>

#define EPS 1e-7
#define INF 4096
#define BASE 30
int hi[60];
int r;

double tim(int x, int h)
{
	x -= BASE; if (x < 0) x++;
	if (x > r || x < -r) return INF;  
	return h+r-sqrt((double)(r*r-x*x));
}

int main()
{
	int n, x, x1, x2, h;
	double min, t;

	while (scanf("%d%d", &r, &n) && r) {
		memset(hi, 0, sizeof(hi));
		while (n-- > 0) {
			scanf("%d%d%d", &x1, &x2, &h); x1 += BASE, x2 += BASE;
			for (x = x1; x < x2; x++) if (hi[x] < h) hi[x] = h;
		}
		min = INF;
		for (x = BASE-r; x < BASE+r; x++) {
			t = tim(x, hi[x]);
			if (fabs(t) <= EPS) { min = 0; break; }
			if (min-t > EPS || t <= min) min = t;
		}
		printf("%.4lf\n", min);
	}
	return 0;
}