#include <bits/stdc++.h>
using namespace std;
int INF = 1000;
int main(){
  cout << fixed << setprecision(5);
  while (1){
    int r, n;
    cin >> r >> n;
    if (r == 0 && n == 0){
      break;
    }
    vector<int> H(40, 0);
    for (int i = 0; i < n; i++){
      int xl, xr, h;
      cin >> xl >> xr >> h;
      xl += 20;
      xr += 20;
      for (int j = xl; j < xr; j++){
        H[j] = max(H[j], h);
      }
    }
    double ans = INF;
    for (int i = 20 - r; i < 20 + r; i++){
      ans = min(ans, H[i] + r - sqrt(pow(r, 2) - pow(min(abs(i - 20), abs(i - 19)), 2)));
    }
    cout << ans << endl;
  }
}
