#include<bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;

int n,r;
typedef pair<int,int> P;
map<int,map<int,double> > height;

bool judge(double base)
{
  for(int x=-r;x<r;x++)
    {
      double y=height[x][x+1]-base;
      if(x*x+y*y<r*r)
	{
	  return true;
	}
      if((x+1)*(x+1)+y*y < r*r)
	{
	  return true;
	}
    }
  return false;
}
int main(int argc,char const* argv[])
{
  while(cin >> r >> n && r)
    {
      height.clear();
      double lx,rx,h;
      for(int i=0;i<n;i++)
	{
	  cin >> lx >> rx >> h;
	  for(int x=lx;x<rx;x++)
	    {
	      height[x][x+1]=max(h,height[x][x+1]);
	    }
	}
      bool end=false;
      double base=-r;
      double t=0.0,step=0.0001;
      while(1)
	{
	  base+=step;
	  end=judge(base);
	  if(end) break;
	  t+=step;
	}
      cout <<fixed << setprecision(9) << t << endl;
    }
  return 0;
}

