#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

double r;

double calc(int x, int h){
     return h-sqrt(pow(r,2)-pow(x,2))+r;
}

int main(){
    int n;
    int map[50];
    while(cin>>r>>n,r!=0){
        fill(map, map+50,0);
        int xl,xr,h;
        for(int i=0;i<n;i++){
            cin>>xl>>xr>>h;
            for(int x=xl;x<xr;x++){
                if(map[x+25]<h)map[x+25]=h;
            }
        }
        double ans=calc(0,map[25]);
        for(int x=floor(-r)+1;x<=ceil(r)-1;x++){
            ans=min({ans,calc(x,map[25+x-1]),calc(x,map[25+x])});
        }
        cout.precision(8);
        cout<<fixed;
        cout<<ans<<endl;
    }
    return 0;
}