#include <stdio.h>
#include <math.h>
#define rep(i,n) for(i=0;i<(int)(n);i++)
#define X 100

double min(double x, double y){
  return x > y ? y : x;
}
double max(double x, double y){
  return x > y ? x : y;
}

int main(){
  int n;
  double r;
  while(scanf("%lf%d", &r, &n) , n){
    int x;
    double h[1000]={};
    int i;
    rep(i,n){
      int x1, x2, y;
      scanf("%d%d%d", &x1, &x2, &y);
      x1+=X, x2+=X;
      for(x=x1;x<x2;x++){
	h[x] = max(h[x], y);
      }
    }
    double ans = 100000;
    for(x=X-r;x<X+r;x++){
      double my = h[x];
      double dx = x < X ? X-x-1 : X-x;
      double t = my-sqrt(r*r-dx*dx)+r;
      //printf("%lf %lf %lf\n", my, dx, t);
      ans = min(ans, t);
    }
    printf("%.10lf\n",ans);
  }
}