#include<bits/stdc++.h>
using namespace std;
int hs[100][100];
int main(){
  int n;
  double r;
  while(cin>>r>>n,r+n){
    memset(hs,0,sizeof(hs));
    for(int i=0;i<n;i++){
      int x1,x2,h;
      cin>>x1>>x2>>h;
      x1+=20;
      x2+=20;
      for(int i=x1;i<x2;i++){
	for(int j=0;j<=h;j++)
	  hs[i][j]=1;
      }
    }
    auto check = [&](double t){
      for(int i=0;i<r;i++){
	double x=i;
	int y=sqrt(r*r-x*x)+t+1-r;
	//cout<<i<<" "<<t<<" "<<y<<endl;
	if(y<=0)continue;
	if(!hs[i+20][y])return false;
	if(!hs[-i+20-1][y])return false;
     
      }
      return true;
    };
    double ub=100,lb=0,mid;
    for(int i=0;i<200;i++){
      mid=(ub+lb)/2;
      if(check(mid))lb=mid;
      else ub=mid;
    }
    cout<<fixed<<setprecision(12)<<lb<<endl;
  }
  return 0;
}

