#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

double dist(double x1,double y1,double x2,double y2){
    return pow(x2-x1,2) + pow(y2-y1,2);
}

int main(){
    int r,n;
    while(cin >> r >> n,r|n){
        vector<int> height(41,0);
        rep(i,n){
            int a,b,h;
            cin >> a >> b >> h;
            a+=20,b+=20;
            for(int i=a;i<b;i++){
                height[i]=max(height[i],h);
            }
        }
        int flag=0;
        for(double c=-r;c<=20.0;c+=0.0005){
            for(int i=-r;i<=r;i++){
                if(dist((double)i,(double)min(height[i+20],height[i+20-1]),0.0,c)<(double)r*(double)r){
                    cout << c+r << endl;
                    flag=1;
                    break;
                }
            }
            if(flag)break;
        }
    }
    return 0;
}
