#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int y[101],r,n;

double mk_dis(int x1,int h,double cy){
  return sqrt(x1*x1+(h-cy)*(h-cy));
}

bool check(double cy){
  cy=(int)(cy*100000)/100000.0;
  double x=fabs(sqrt(r*r-cy*cy));
  if(cy>=0)x=r;
  int L=(-x-0.999999),R=(x+0.999999),hb[101]={};
  for(int i=L+50;i<R+50;i++)
    if(i>=50){
      if(mk_dis(i-50,y[i],cy)>=r)hb[i]++;
    }
    else {
      if(mk_dis(i-49,y[i],cy)>=r)hb[i]++;
    }
  
  for(int i=L+50;i<R+50;i++)if(!hb[i])return false;
  return true;
}

int main(){
  while(1){
    cin>>r>>n;
    if(!r&&!n)break;
    memset(y,0,sizeof(y));
    for(int i=0;i<n;i++){
      int x1,x2,h;
      cin>>x1>>x2>>h;
      for(int j=x1;j<x2;j++) y[j+50]=max(y[j+50],h);
    }
    double ans;
    for(ans=0;check(ans-r);ans+=0.0001);
    cout << ans<<endl;
  }
  return 0;
}