#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;

int r, n;

double calc(int a, int height){
    double x = sqrt((double)(r * r - a * a));
    return (double)height - x;
}

int main() {
    while (1) {
        cin >> r >> n;
        if(r + n == 0) break;
        double ans = 20.0;
        int height[41] = {};
        rep(i, 0, n){
            int xl, xr, h;
            cin >> xl >> xr >> h;
            xl += 20;
            xr += 20;
            rep(j, xl, xr){
                height[j] = max(height[j], h);
            }
        }
        rep(i, 20 - r, 20 + r){
            int a = abs(i - 20);
            double limit = calc(a, height[i]);
            ans = min(ans, limit);
            
            // cout << i << ' ' << height[i] << ' ' << a << ' ' << limit << endl;

            int a2 = abs(i + 1 - 20);
            double limit2 = calc(a2, height[i]);
            ans = min(ans, limit2);
        }
        printf("%.10f\n", ans + r);
    }
}
