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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

double EPS = 1e-10;

// 誤差を考慮してた考慮して足し算を行う
double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a) + abs(b))) return 0;
  return a+b;
}
struct P {
  double x,y;
  P(){}
  P(double x, double y): x(x), y(y) {}

  P operator + (P p){
    return P(add(x,p.x), add(y,p.y));
  }

  P operator - (P p){
    return P(add(x,-p.x), add(y,-p.y));
  }

  P operator * (double d){
    return P(x * d, y * d);
  }

  double dot(P p){ //内積
    return add(x * p.x, y * p.y);
  }

  double det(P p) { //外積
    return add(x * p.y , -y * p.x);
  }

  double p_abs(){return sqrt(p_norm());}
  double p_norm() { return x * x + y * y; }

};

// 線分p1-p2上に点qがあるか判定
bool on_seg(P p1, P p2, P q){
  return (p1-q).det(p2 - q) == 0 && (p1 - q).dot(p2 - q) <= 0;
}

// 直線p1-p2と直線q1-q2 の交点
P intersection(P p1, P p2, P q1, P q2){
  return p1 + (p2 - p1) * ((q2 - q1).det(q1- p1) / (q2 - q1).det(p2 - p1));
}

struct Segment{
  P p1, p2;
};

typedef Segment Line;

double getDistanceLP(Line l, P p){
  return abs(((l.p2 - l.p1).det(p - l.p1))) / (l.p2 - l.p1).p_abs();
}

//線分sと点pの距離
double getDistanceSP(Segment s, P p){
  if((s.p2 - s.p1).dot(p - s.p1) < 0.0) return (p - s.p1).p_abs();
  if((s.p1 - s.p2).dot(p - s.p2) < 0.0) return (p - s.p2).p_abs();
  return getDistanceLP(s,p);
}

void solve(double r, ll n , VLL &xmi, VLL &xma ,VLL & h){
  map<PII,ll> maxH;
  rep(i,n){
    for(int x = xmi[i]; x < xma[i]; x++){
      maxH[PII(x,x+1)] = max(maxH[PII(x,x+1)], h[i]);
    }
  }

  vector<Segment> s;
  P prev = P(-23,0);
  FOR(x,-22,22){
    if(prev.y == maxH[PII(x,x+1)]) continue;
    else{
      Segment tmp;
      tmp.p1 = prev, tmp.p2 = P(x,prev.y);
      s.push_back(tmp);
      prev = P(x,maxH[PII(x,x+1)]);
    }
  }
  Segment tmp;
  tmp.p1 = prev, tmp.p2 = P(22,0);
  s.push_back(tmp);

  //rep(i,s.size()) cout << s[i].p1.x << "," << s[i].p1.y << "    " << s[i].p2.x << "," << s[i].p2.y << endl;;
  for(double o = -r;; o+=0.0005){
    P O(0,o);
    rep(i,s.size()){
      if(getDistanceSP(s[i],O) + EPS >= r){
        continue;
      }
      else{
        printf("%0.5lf\n",o+r);
        return;
      }
    }
  }
  return;
}

int main(){

  ll r;
  int n;
  while(true){
    cin >> r >> n;
    if(r == 0 && n == 0) break;
    VLL xmi(n) , xma(n) , h(n);
    rep(i,n){
      cin >> xmi[i] >> xma[i] >> h[i];
    }
    solve(r,n,xmi,xma,h);
  }
  return 0;
}



Measured memory_bytes: 3148