#include <bits/stdc++.h>

#define DEBUG(C) cerr << #C << " = " << C << endl

using namespace std;

const int MAX = 30;
int xl[MAX], xr[MAX], h[MAX];
int maxHeight[MAX * 2 + 10];

bool solve() {
  int r, n;
  scanf("%d%d", &r, &n);
  if (r == n && r == 0) {
    return false;
  }
  memset(maxHeight, 0, sizeof(maxHeight));
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", xl + i, xr + i, h + i);
    for (int j = xl[i] + MAX; j < xr[i] + MAX; j++) {
      maxHeight[j] = max(maxHeight[j], h[i]);
    }
  }
  double high = MAX, low = 0;
  for (int cnt = 0; cnt < 100; cnt++) {
    const double mid = (high + low) / 2;
    bool out = false;
    
    for (int i = MAX - r + 1; i < MAX + r; i++) {
      double nowHeight = 1. * mid + sqrt(r * r - (i - MAX) * (i - MAX)) - r;
      if (maxHeight[i - 1] < nowHeight || maxHeight[i] < nowHeight) {
        out = true;
        break;
      }
    }
    
    if (out) {
      high = mid;
    } else {
      low = mid;
    }
  }
  printf("%.10lf\n", low);
  return true;
}

int main() {
  while (solve()) {}
  return 0;
}