// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
#define double long double
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-20, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(16) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

using PD = pair<double, double>;

ll T;

double get_v0(double y) {
  double W = T/2., H = y;
  double vx = W / sqrt(2 * H);
  double vy = sqrt(2 * H);
  return sqrt(vx * vx + vy * vy);
}

double f(double x, double y) {
  double a = x, b = y, W = T/2.;
  return b * W * W / (2 * a * W - a * a);
}

PD solve1(vector<PD> v) {
  each(p, v) swap(p.first, p.second);
  sort(all(v));
  double res = 0;
  double r = -linf;
  ll cnt = 0;
  each(p, v) {
    if (r >= p.second-eps) continue;
    r = p.first;
    res += get_v0(p.first);
    ++cnt;
  }
  // cout << cnt << endl;
  return PD(res, r);
}
PD solve2(vector<PD> v) {
  sort(all(v), greater<PD>());
  double res = 0;
  double l = linf;
  ll cnt = 0;
  each(p, v) {
    if (l <= p.second-eps) continue;
    l = p.first;
    res += get_v0(p.first);
    ++cnt;
  }
  // cout << cnt << endl;
  return PD(res, l);
}

void solve() {
  ll n; cin >> T >> n;
  vector<ll> X(n), L(n), H(n);
  rep(i, n) cin >> X[i] >> L[i] >> H[i];
  vector<PD> left, right, middle;
  double v = sqrt(T/2.);
  double tmid = T / v;
  double th = T / 4.;
  rep(i, n) {
    double l = f(X[i], L[i]);
    double r = f(X[i], H[i]);
    if (r <= th+eps) {
      left.eb(l, r);
    }
    else if (l >= th-eps) {
      right.eb(l, r);
    }
    else {
      middle.eb(l, r);
    }
    // cout << X[i] << " " << L[i] << " " << l << " " << r << endl;
  }
  // cout << left.size() << " " << right.size() << endl;
  auto r1 = solve1(left);
  auto r2 = solve2(right);
  // cout << r1.first << " " << get_v0(0.1973955598) << endl;
  double ans = r1.first + r2.first;
  double l = r1.second;
  double r = r2.second;
  bool flag = false;
  each(p, middle) {
    if (l+eps < p.first && p.second < r-eps) {
      flag = true;
      break;
    }
  }
  // 45度とばす
  if (flag) {
    ans += get_v0(th);
  }
  cout << ans << endl;
}



Measured memory_bytes: 11176