#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

double r;
ll n;
ll ymax[100][2];

int main(){
	while(cin >> r >> n && r){
		rep(i,100)rep(j,2)ymax[i][j] = 0;
		double ans = INF;
		rep(i,n){
			ll lb,ub,h;
			cin >> lb >> ub >> h;
			lb += 50;
			ub += 50;
			FOR(i,lb,ub+1){
				if(i != lb)ymax[i][0] = max(ymax[i][0],h);
				if(i != ub)ymax[i][1] = max(ymax[i][1],h);
			}
		}
		FOR(i,50-r+1,50+r){
			double y = min(ymax[i][0],ymax[i][1]);
			double absx = abs(i-50);
			double g = sqrt(r*r - absx*absx);
			// cout << i << " " << y << endl;
			ans = min(ans,r + y - g);
		}
		printf("%.10lf\n",ans);
	}

}
