#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
 */
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
//manip
template<class T> bool chmax(T &a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, T b) {if (a > b) {a = b; return 1;} return 0;}
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end())
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power(T a, T b)
{return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
//output
#define out(a) cout << a << endl
#define outa(a, n) rep(i, n) cout << a[i] << " "; cout << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl;
#define outp(v) rep(i, SZ(v)) cout << v[i].F << " " << v[i].S << endl
#define outc(s, t) cout << fixed << setprecision(10) << (double)(t - s) / CLOCKS_PER_SEC << endl
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
//algorithm (have library)
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0, while r < n




bool comp(pair<int, pii> a, pair<int, pii> b) {
    if (a.S.F != b.S.F) return a.S.F > b.S.F;
    return a.S.S > b.S.S;
}

int main() {
    //cast caution
    //look constraints always
    cin.tie(0); ios::sync_with_stdio(false);
    
    
    
    
    
    
    int r, n;
    while (cin >> r >> n && r) {
        int xl[n], xr[n], h[n];
       
        rep(i, n) {
            cin >> xl[i] >> xr[i] >> h[i];
            
        }
        
        double ans = inf;
        rep3(left, -20, 20) {
            if (left + 1 <= -r || left >= r) continue;
            int flg = 0;
            double ans_tmp = 0;
            rep(i, n) {
                
                if (xl[i] <= left && left + 1 <= xr[i]) {
                    flg = 1;
                    double tmp = h[i];
                    
                    int x = min(abs(left), abs(left + 1));
                    //cout << tmp << " " << (-r + sqrt(r * r - x * x)) << endl;
                    tmp = tmp - (-r + sqrt(r * r - x * x));
                    //cout << i << " " << x << " " << left << " " << tmp << endl;
                    chmax(ans_tmp, tmp);
                }
            }
            if (flg) {
                chmin(ans, ans_tmp);
            } else {
                double tmp = 0;
                int x = min(abs(left), abs(left + 1));
                tmp = tmp - (-r + sqrt(r * r - x * x));
                chmin(ans, tmp);
            }
            
        }
        cout << ans << endl;
        
        
    }
    
   
    
    
    
}
//cast caution

/*
 
 一番手前のとこ見つけたらいいんじゃね？
 
 いや、難しい
 配列作ったらsample1
 -1のとこ3やし0のとこも3
 
 
 
 
 
 ビルごとに見るか
 
 円の位置二分探索する
 各ビルに対し、左端、右端のちょい左、右を見て円が範囲内か
 
 いや、他のビルも含めて範囲内か見るのむずい
 
 その座標を保存して全探索するか
 いや、角度むず
 
 
 
 
 
 すべてのx範囲1の区間見るか
 
 ダメだったら配列でindex2倍にしたら
 -1 -> -2, 0 -> 0, 1 -> 2
 になる
 
 sample1
 -3  -2  -1   0   1   2   3
  0 0 3 3 3 0 3 3 3 0 3 3 3 0
 
 あれ、わからんわ
 
 
 */
 
 
 
 
 
 




Measured memory_bytes: 3264