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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int rad,n;cin>>rad>>n;
  while(rad!=0||n!=0)
  {
    vector<int> l(n);
    vector<int> r(n);
    vector<int> h(n);
    int i,j;
    rep(i,n)cin>>l[i]>>r[i]>>h[i];
    rep(i,n)
    {
      l[i]+=20;
      r[i]+=20;
    }
    vector<int> maxh(20*2,0);
    rep(i,n)
    {
      rep(j,20*2)
      {
        if(j<l[i]||j>=r[i])continue;
        maxh[j]=max(maxh[j],h[i]);
      }
    }
    double ans=100.0;
    for(i=20-rad;i<=20+rad;i++)
    {
      int useh;
      if(i==20-rad)useh=maxh[i];
      else if(i==20+rad)useh=maxh[i-1];
      else useh=min(maxh[i-1],maxh[i]);
      int x=i-20;
      double kans=useh+rad-sqrt(rad*rad-x*x);
      ans=min(ans,kans);
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
    cin>>rad>>n;
  }
}

