#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>

using namespace std;

const int diff = 20;

bool solve() {
    int R, N;
    cin >> R >> N;
    if (R == 0) return false;

    vector<int> H(41, 0);
    for (int i = 0; i < N; ++i) {
        int l, r, h;
        cin >> l >> r >> h;
        l += diff, r += diff;
        for (int x = l; x < r; ++x) {
            H[x] = max(H[x], h);
        }
    }

    double ans = 20;
    for (int x = -R + 1; x < R; ++x) {
        int xi = x + diff;
        int h = min(H[xi - 1], H[xi]);
        ans = min(ans, h - sqrt(R * R - x * x) + R);
    }
    cout << fixed << setprecision(10) << ans << endl;
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}
