#include <bits/stdc++.h>
using namespace std;
template<class T = int> using V = vector<T>;

int main() {
    int r, n;
    while (cin >> r >> n, r) {
        V<> a(40);
        while (n--) {
            int l, r, h; cin >> l >> r >> h;
            l += 20, r += 20;
            for (int i = l; i < r; ++i) a[i] = max(a[i], h);
        }
        auto chk = [&](double t) -> bool {
            for (int x = 20 - r + 1; x < 20 + r; ++x) {
                double y = min(a[x - 1], a[x]) + r - t;
                if (sqrt(r * r - (x - 20) * (x - 20)) > y) return false;
            }
            return true;
        };
        double ok = 0, ng = 100;
        for (int _ = 0; _ < 100; ++_) {
            double mid = (ok + ng) / 2;
            (chk(mid) ? ok : ng) = mid;
        }
        cout << fixed << setprecision(15) << ok << '\n';
    }
}
