// Original C++ solution (slower):
#include "bits/stdc++.h"

using namespace std;

typedef long double ld;

typedef complex<ld> Point;

const ld eps = 1e-9, pi = acos(-1.0);



// ??´????????????

class Line {

public:

	Point a, b;

	Line() : a(Point(0, 0)), b(Point(0, 0)) {}

	Line(Point a, Point b) : a(a), b(b) {}

	Point operator[](const int _num) {

		if (_num == 0)return a;

		else if (_num == 1)return b;

		else assert(false);

	}

};

// ????????????????????????

bool eq(ld a, ld b) {

	return (abs(a - b) < eps);

}

// ??????

ld dot(Point a, Point b) {

	return real(conj(a) * b);

}



// ??????

ld cross(Point a, Point b) {

	return imag(conj(a) * b);

}

// ????????????

class Circle {

public:

	Point p;

	ld r;

	Circle() : p(Point(0, 0)), r(0) {}

	Circle(Point p, ld r) : p(p), r(r) {}

};

// ??????????¶?

Point proj(Line l, Point p) {

	ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);

	return l.a + t * (l.a - l.b);

}

// ??´?????¨???????????¢

ld dist_lp(Line l, Point p) {

	return abs(p - proj(l, p));

}

// ?????????????????????

bool isis_sp(Line s, Point p) {

	return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps);

}

// ?????¨??´????????????

vector<Point> is_lc(Circle c, Line l) {

	vector<Point> res;

	ld d = dist_lp(l, c.p);

	if (d < c.r + eps) {

		ld len = (d > c.r) ? 0.0 : sqrt(c.r * c.r - d * d); //safety;

		Point nor = (l.a - l.b) / abs(l.a - l.b);

		res.push_back(proj(l, c.p) + len * nor);

		res.push_back(proj(l, c.p) - len * nor);

	}

	return res;

}

// ?????¨??????????????¢

vector<Point> is_sc(Circle c, Line l) {

	vector<Point> v = is_lc(c, l), res;

	for (Point p : v)

		if (isis_sp(l, p)) res.push_back(p);

	return res;

}





int dx[3] = { 0,1,0 };

int dy[3] = { -1,0,1 };

// dir: ??????0, ??????1, ??????2

void kado_mituketu(int x,int y,vector<pair<int, int>>& kado, bool grid[80][80],int dir) {

	if (x >= 61) {

		kado.push_back({ x,y + 1 });

		return;

	}

	for (int i = 2; i >= 0;i--) {

		if (i == 2 && dir == 0)continue;

		if (grid[x + dx[i]][y + dy[i]] == true) {

			if (dir != i) {

				if (i != 0) {

					if (dir != 0) { kado.push_back({ x,y + 1 }); }

					else { kado.push_back({ x + 1,y + 1 }); }

				}

				else {

					if (dir == 2) { kado.push_back({ x,y + 1 }); }

					kado.push_back({ x + 1,y + 1 });

				}

				dir = i;

			}

			kado_mituketu(x + dx[i], y + dy[i], kado, grid, dir);

			return;

		}

	}

	return;

}



int main() {

	cin.tie(0);ios::sync_with_stdio(false);

	int r, n;

	while (cin >> r >> n, r | n) {

		bool grid[80][80] = { false };

		for (int i = 0; i < n;i++) {

			int xl, xr, h; cin >> xl >> xr >> h;

			for (int x = xl; x < xr;x++) {

				for (int hh = 0;hh < h;hh++) {

					grid[40 + x][40+hh] = true;

				}

			}

		}

		for (int i = 0; i <= 42;i++) grid[19 + i][39] = true;

		vector<pair<int, int>> kado;

		kado.push_back({ 20,40 });

		kado_mituketu(20,39,kado, grid, 1);

		double maxh = -1;

		for (int h = -1; h <= 22;h++) {

			if (grid[40][40 + h]) maxh = max(maxh, (double)(h + 1));

			if (grid[39][40 + h])maxh = max(maxh, (double)(h + 1));

		}

		for (int i = 0; i < kado.size();i++) {

			kado[i].first -= 40;kado[i].second -= 40;

		}

		double low = -r, up = maxh;

		for(int i = 0; i < 100;i++){

			double mid = (low + up) / 2;

			Circle cir(Point(0, mid), r);

			bool f = false;

			for (int i = 0; i < kado.size() - 1;i++) {

				Line line(Point(kado[i].first, kado[i].second), Point(kado[i + 1].first, kado[i + 1].second));

				auto pp = is_sc(cir, line);

				if (pp.size() == 0) continue;

				bool ff = false;

				for (auto p : pp) {

					if ((p.imag() - mid) > eps) {

						up = mid;

						f = true;

						ff = true;

						break;

					}

				}

				if (ff) break;

			}

			if (f) continue;

			low = mid;

		}

		cout << fixed << setprecision(6) << low + r << endl;

	}

}

// Optimized solution to the same problem (faster):
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int INF = 1e9;

const ll LINF = 1e18;

template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }

template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }

template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }

template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }



/*

 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1194&lang=jp>

 問題文============================================================

 =================================================================

 解説=============================================================

 ================================================================

 */

double R;

int n;

int base = 50;

bool building[55][100];

double solve(){

    fill(*building,*building+100*55,0);

    double res = 0;

    vector<int> xl(n),xr(n),h(n);

    for(int i = 0; i < n;i++) cin >> xl[i] >> xr[i] >> h[i];

    for(int i = 0; i < n;i++){

        xl[i] += base; xr[i] += base;

        for(int j = xl[i]; j < xr[i];j++){

            for(int k = 0; k < h[i];k++){

                building[k][j] = true;

            }

        }

    }

//    for(int i = 10; i >= 0; i--){

//        for(int j = 40; j <= 60; j++){

//            cout << building[i][j];

//        }

//        cout << endl;

//    }

    

    double l = 0,r = 50;

    for(int i = 0; i < 50;i++){

        double m = (l+r)/2;

        bool ok = true;

        for(int x = -R; x < 0; x++){

            double from = R - sqrt(R*R-(abs(x)-1)*(abs(x)-1));

            double H = m - from;

            if(H < 0) continue;

            if(building[(int)H][x+base] == 0) ok = false;

        }

        for(int x = 0; x < R; x++){

            double from = R - sqrt(R*R-x*x);

            double H = m - from;

            if(H < 0) continue;

            if(building[(int)H][x+base] == 0) ok = false;

        }

        if(ok){

            l = m;

        }else{

            r = m;

        }

    }

    res = l;

    return res;

}

int main(void) {

    cin.tie(0); ios_base::sync_with_stdio(false);

    while(cin >> R >> n){

        if(n == 0 && R < 1e-9) break;

        cout << fixed << setprecision(4) << solve() << endl;

    }

    return 0;

}




// Fastest known solution for this problem: