import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int R, N;
    int[] L = new int[41];
    const P = 20;
    bool input() {
        scanf("%d %d\n", &R, &N);
        if (R == 0 && N == 0) return false;
        L[] = 0;
        foreach (i; 0 .. N) {
            int l, r, h;
            scanf("%d %d %d\n", &l, &r, &h);
            foreach (j; l .. r) {
                L[j + P] = max(L[j + P], h);
            }
        }
        return true;
    }
    bool C(double t) {
        if (min(L[P - 1], L[P]) < t) return false;
        for (int x = -19; x <= 20; x++) {
            int y = min(L[x + P], L[x + P - 1]);
            //writeln([t]);
            //writeln([x, y]);
            if (x * x + (t - R - y) * (t - R - y) < R * R) return false;
        }
        return true;
    }
    void solve() {
        double lb = 0, ub = 21;
        foreach (_; 0 .. 100) {
            double mid = (lb + ub) / 2;
            if (C(mid)) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        writefln("%.4f", lb);
    }
    while (input) solve;
}