#include <bits/stdc++.h>
using namespace std;

struct Rect {
    int l, r, h;

    Rect(){}
    ~Rect(){}

    Rect (int a, int b, int c):
        l(a), r(b), h(c) {}

    bool operator < (const Rect& o) const {
        return r == o.r ? l < o.l : r < o.r;
    }
};

int main() {
    while (true) {
        int r, n;
        cin >> r >> n;

        if (r == 0 && n == 0){
            break;
        }

        vector<Rect> rects(n);

        for (int j = 0; j < n; ++j) {
            cin >> rects[j].l >> rects[j].r >> rects[j].h;
        }

        int dum[90];
        int* heights = dum + 45;
        fill(dum, dum + 90, 0);

        for (int j = 0; j < n; ++j) {
            for (int x = 2 * rects[j].l; x <= 2 * rects[j].r; ++x) {
                heights[x] = max(heights[x], rects[j].h);
            }
        }

        heights[-2*r-1] = numeric_limits<int>::max();
        heights[2*r+1] = numeric_limits<int>::max();

        double ret = numeric_limits<double>::max();

        for (int x = -2 * r; x <= 2 * r; x += 2) {
            int h = min(heights[x], min(heights[x-1], heights[x+1]));
            ret = min(ret, h + r - sqrt(r * r - x * x / 4));
        }

        printf("%.4f\n", ret);
    }
    return 0;
}