#include<bits/stdc++.h>
using namespace std;
int R, N; 
int x1,x2,h;
int B[50];
double ans = 10000.0;

double b(double x) {
	return (double) B[(int) (x + 25.0)];
	
}

double sun(double x) {
	double r = R;
	return sqrt(r * r - x * x) - r;
}

double f(double x) {
	return b(x) - sun(x);
}

int main() {
	cin >> R >> N;
	while(R + N) {
		ans = 10000000.0;
		for (int i = 0; i < 50; i ++) {
			B [i] = 0;
		}
		for (int i = 0; i < N; i++) {
			cin >> x1 >> x2 >> h;
			x1 += 25;
			x2 += 25;
			for (int x = x1; x < x2; x++ ) {
				B[x] = max(B[x], h);
			}
		}
		double r = R;
		for (double x = -r; x < r; x += 0.00001) {
			ans = min(ans, f(x));
		}
		printf("%f\n",ans);
		
		cin >> R >> N;
	}
}
