#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;

double calc(double h, double x, double r) {
    return h + sqrt(r * r - x * x);
}


int main() {
    int rad, n;
    while (cin >> rad >> n, rad + n) {
	vector<int> X1(n), X2(n), Y(n);
	for (int i = 0; i < n; i++) {
	    cin >> X1[i] >> X2[i] >> Y[i];
	}
	double l = 0, r = 1000, ans = 0.0;
	while (abs(l - r) >= 1e-6) {
	    double mid = (l + r) / 2;
	    vector<bool> H(rad * 2, false);
	    for (int x = -rad; x < rad; x++) {
		if (max(calc(mid - rad, x, rad), calc(mid - rad, x + 1, rad)) <= 0) {
		    H[x + rad] = true;
		}
	    }
	    
	    
	    for (int i = 0; i < n; i++) {
		for (int x = -rad; x < rad; x++) {
		    if (X1[i] <= x && x < X2[i]) {
			double mn = min(Y[i] - calc(mid - rad, x, rad), Y[i] - calc(mid - rad,  x + 1, rad));
			if (mn >= 0) {
			    H[rad + x] = true;
			}
		    }
		}
	    }
	    bool ok = true;
	    for (int i = 0; i < rad * 2; i++) {
		ok &= H[i];
	    }
	    if (ok) {
		ans = mid;
		l = mid;
	    }
	    else {
		r = mid;
	    }
	}
	cout << fixed << setprecision(10) << ans << endl;
    }
    return 0;
}

