#include<stdio.h>
#include<math.h>
#define MAX_X 21
int hights_m[MAX_X];
int hights_p[MAX_X];

/* 
2 6
-3 3 1
-2 3 2
-1 3 3
0 3 4
1 3 5
2 3 6
 */

double calc_dis(double x, double y)
{
  return sqrt(x * x + y * y);
}
double min = 1000000.0, min_x, min_y;


void calc_min(double x, double y)
{
  double from_origin = calc_dis(x, y);
  if(from_origin == min)
    {
      if(min_y < y)
	{
	  min = from_origin;
	  min_x = x;
	  min_y = y;
	}
    }
  else if(from_origin < min)
    {
      min = from_origin;
      min_x = x;
      min_y = y;
    }
  
}


void make_points()
{
  int i, p = 0, prev = 0;
  double x, y;
  for(i = 0; i < MAX_X; i++)
    {
      /* [0] [1] [2]*/
      if(hights_m[i] != prev)
	{
	  x = (double)(i - MAX_X);
	  y = (double)prev;
	  calc_min(x, y);

	  y = (double)hights_m[i];
	  calc_min(x, y);
	}
      prev = hights_m[i];
    }
  for(i = 0; i < MAX_X; i++)
    {
      /* 0 [0] 1 [1] 2 [2] 3*/
      if(hights_p[i] != prev)
	{
	  x = (double)i;
	  y = (double)prev;
	  calc_min(x, y);

	  y = (double)hights_p[i];
	  calc_min(x, y);
	}
      else if(i == 0)
	{
	  x = 0.0;
	  y = (double)hights_p[i];
	  calc_min(x, y);
	}
      prev = hights_p[i];
    }
}




int main(void)
{
  int n, r, i, j, right, left, hight;

  while(scanf("%d %d", &r, &n), n != 0 && r != 0)
    {
      for(i = 0; i < MAX_X; i++)
	{
	  hights_m[i] = 0;
	  hights_p[i] = 0;
	}
  
      for(i = 0; i < n; i++)
	{
	  scanf("%d %d %d", &left, &right, &hight);
	  for(j = left; j < right; j++)
	    {
	      if(j < 0)
		if(hights_m[MAX_X + j] < hight)
		  hights_m[MAX_X + j] = hight;
		else
		  ;
	      else
		if(hights_p[j] < hight)
		  hights_p[j] = hight;
	    }
	}

      make_points();

      //      printf("min = %lf, (%lf, %lf)\n", min, min_x, min_y);

      double l = sqrt((double)r * (double)r - min_x * min_x);
      printf("%.4lf\n", min_y - l + r);
      min = 1000000.0;
      min_x = 1000000.0;
      min_y = 1000000.0;
    }
  return 0;
}