#include <stdio.h>
#include <math.h>

#define MIN_X (-20)
#define MAX_X   20

int hgt[MAX_X - MIN_X];
#define height(x) (hgt[(x) - MIN_X])

double solve(int r)
{
  int x, x0;
  double y, t;
  double min = height(0); /* the time when the sunlight comes at x=0 */
  for (x = -r; x < r; x++) {
    x0 = (x < 0 ? x + 1 : x);
    y = sqrt(r * r - x0 * x0) - r; /* the top of the sun at x0 */
    t = height(x) - y;
    if (min > t) min = t;
  }
  return min;
}

int main()
{
  int r, n, h, i, x, x1, x2;
  for (;;) {
    scanf("%d%d", &r, &n);  /* radius, # of bld. */
    if (r == 0 && n == 0) break;

    for (x = MIN_X; x < MAX_X; x++) height(x) = 0; /* initialize */
    for (i = 0; i < n; i++) {
      scanf("%d%d%d", &x1, &x2, &h); /* left, right, height */
      for (x = x1; x < x2; x++) {
        if (height(x) < h) height(x) = h;
      }
    }
    printf("%.4f\n", solve(r));
  }
  return 0;
}