#include <iostream>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){

  int r,n,x1,x2,h,i,j;
  
  while(cin>>r>>n,r){
  int build[41][2]={0};
  for(i=0;i<n;i++){
    cin>>x1>>x2>>h;
    x1+=20; x2+=20;
    for(j=x1+1;j<=x2-1;j++) for(int k=0;k<2;k++) build[j][k]=max(build[j][k],h);
    build[x1][0]=max(build[x1][0],h);
    build[x2][1]=max(build[x2][1],h);
  }
  int bu[41]={0};
  for(i=0;i<41;i++) bu[i]=min(build[i][0],build[i][1]);
  double c[41],result=100;
  for(i=-r+1;i<=r-1;i++) c[i+20]=sqrt(r*r-i*i)-r;
  for(i=20-r+1;i<=20+r-1;i++){
    //cout<<bu[i]-c[i]<<" ";
    //cout<<endl;
    result=min(result,bu[i]-c[i]);
  }
  cout<<result<<endl;
  }
  return 0;

}