#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */
namespace utils{

    class Repeater{
        int st;
        int ed;
        int d;
    public:
        class rep_iterator{
            int i; int d;
        public:
            rep_iterator(int x, int pd) :i(x), d(pd) {}

            int& operator*(){ return i; }
            bool operator==(const rep_iterator& k) const { return i == k.i; }
            bool operator!=(const rep_iterator& k) const { return i != k.i; }
            rep_iterator& operator++(){ i+=d; return *this; }
        };

        explicit Repeater(int N) :st(0), ed(N), d(1) {}
        Repeater(int b, int e) :st(b), ed(e), d(1) {if(st > ed){ st--; ed--; d = -1; } }

        rep_iterator begin() const{ return rep_iterator(st, d); }
        rep_iterator end() const{ return rep_iterator(ed, d); }

    };

    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
}
using namespace utils;

unordered_map<int, double> init(vector<int> xl, vector<int> xr, vector<int> h, int R){
    unordered_map<int, double> ans;
    for (int i = -R; i < R; ++i) {
        int mx = 0;
        for (int j = 0; j < xl.size(); ++j) {
            if(xl[j] <= i and xr[j] > i){
                mx = max(h[j], mx);
            }
        } // end j
        ans[i] = mx;
    } // end i

    return ans;

}

bool check(double t, int R, const unordered_map<int, double>& walls){
    for (int x = -R; x < R; ++x) {
        double y = sqrt(R*R-x*x) + t - R;
        double y1 = sqrt(R*R - (x+1)*(x+1)) + t  - R;

        if(walls.at(x) < y) return false;
        if(walls.at(x) < y1) return false;
    } // end x
    return true;
}


void sub_main(istream &is) {
    ll R, N;
    is >> R >> N;
    if(!is or R == 0) return;
    vector<int> xl(N), xr(N), h(N);

    for (int i = 0; i < N; ++i) {
        is >> xl[i] >> xr[i] >> h[i];
    } // end i

    auto walls = init(xl, xr, h, R);

    double ok = 0;
    double NG = 20;
    while(NG - ok > 0.000001 ){
        double mid = (ok + NG) / 2.;
        if(check(mid, R, walls)){
            ok = mid;
        }
        else NG = mid;
    }

    cout << ok << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(7);
#ifdef DEBUG
    string test_cases = "test_A.txt";
    cerr << "DEBUG MODE" <<  endl;
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    while(cin) sub_main(cin);
#endif
    return 0;
}



Measured memory_bytes: 3212