#include <bits/stdc++.h>
using namespace std;

vector<double> a(82);
long long r, n;
int fl(int x) { return x + 40; }
int fr(int x) { return x + 41; }
bool g(double t) {
  for (int i = -r; i < r; i++) {
    if (a[fr(i)] < sqrt(r * r - i * i) + t - r) {
      return false;
    }
  }
  for (int i = -r + 1; i <= r; i++) {
    if (a[fl(i)] < sqrt(r * r - i * i) + t - r) {
      return false;
    }
  }
  return true;
}

int main() {
  while (true) {
    cin >> r >> n;
    if (r == 0)
      break;
    for (int i = 0; i < 82; i++)
      a[i] = 0;
    for (int i = 0; i < n; i++) {
      int b, c, h;
      cin >> b >> c >> h;
      for (int j = fr(b); j <= fl(c); j++) {
        a[j] = max(a[j], (double)h);
      }
    }
    double tmin = 0, tmax = 1000;
    for (int l = 0; l < 3000; l++) {
      double t = (tmin + tmax) / 2;
      if (g(t)) {
        tmin = t;
      } else {
        tmax = t;
      }
    }
    printf("%.9lf\n", tmin);
  }
  return 0;
}

