#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

using D = double;
D td;

D single(D w) {
    return sqrt(td * (1.0 / (4 * w) + w));
}

D cost(D lw, D up) {
    D res = min(single(lw), single(up));
    if (lw <= 0.5 && 0.5 <= up) res = min(res, single(0.5));
    return res;
}

template <class I> struct Frac {
    I a, b;
    Frac(I _a = 0) : a(_a), b(1) {}
    Frac(I _a, I _b) {
        I g = __gcd(_a, _b);
        if (_b < 0) g = -g;
        a = _a / g;
        b = _b / g;
    }

    bool operator<(const Frac& r) const { return a * r.b < b * r.a; }
    bool operator>(const Frac& r) const { return r < *this; }
    bool operator==(const Frac& r) const {
        return a * r.b == b * r.a;
    }

    D to_d() const {
        return D(a) / b;
    }
};
using Int = __int128_t;
using F = Frac<Int>;

Int read() {
    ll x;
    cin >> x;
    return Int(x);
}

Int t;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(20);

    t = read();
    td = double(t);
    Int n = read();

    V<F> lw, up, idx;
    for (int i = 0; i < n; i++) {
        Int x = read(), l = read(), h = read();

        F lw_w = F{t * l, 2 * (t * x - x * x)};
        F up_w = F{t * h, 2 * (t * x - x * x)};

        lw.push_back(lw_w);
        up.push_back(up_w);

        idx.push_back(lw_w);
        idx.push_back(up_w);
    }

    sort(idx.begin(), idx.end());
    idx.erase(unique(idx.begin(), idx.end()), idx.end());

    auto get_i = [&](const F& f) {
        return int(lower_bound(idx.begin(), idx.end(), f) - idx.begin());
    };


    int k = int(idx.size());
    VV<int> st(k + 1), ed(k + 1);

    using P = pair<int, int>;
    V<P> rng;
    for (int i = 0; i < n; i++) {
        rng.push_back({get_i(lw[i]), get_i(up[i])});
    }

    sort(rng.begin(), rng.end());
    for (int i = 0; i < n; i++) {
        st[rng[i].first].push_back(i);
        ed[rng[i].second].push_back(i);
    }

    /*for (int i = 0; i < n; i++) {
        cout << rng[i].first << " " << rng[i].second << endl;
    }*/

    struct E {
        int to;
        D dist;
    };
    VV<E> g(n + 1);
    for (int i = n; i >= 1; i--) {
        g[i].push_back({i - 1, 0});
    }
    deque<int> que;

    for (int x = 0; x < k; x++) {
        for (int d: st[x]) {
            que.push_back(d);
        }
        if (!que.empty()) {
            D co = single(idx[x].to_d());
            int l = que.front(), r = que.back() + 1;

            g[l].push_back({r, co});
            //cout << l << " - " << r << " " << co << endl;
        }

        for (int d: ed[x]) {
            while (!que.empty() && que.front() <= d) {
                que.pop_front();
            }
        }

        if (!que.empty()) {
            D co = cost(idx[x].to_d(), idx[x + 1].to_d());
            int l = que.front(), r = que.back() + 1;

            g[l].push_back({r, co});
            //cout << l << " - " << r << " " << co << endl;
        }
    }

    struct Q {
        D key;
        int to;
        bool operator<(Q r) const { return key > r.key; }
    };

    V<D> dist(n + 1, 1e100);
    V<int> vis(n + 1);
    priority_queue<Q> q;
    q.push(Q{0, 0});
    dist[0] = 0;

    while (!q.empty()) {
        Q p = q.top(); q.pop();
        if (vis[p.to]) continue;
        vis[p.to] = true;
        for (E e : g[p.to]) {
            if (p.key + e.dist < dist[e.to]) {
                dist[e.to] = p.key + e.dist;
                q.push(Q{dist[e.to], e.to});
            }
        }
    }

    cout << dist[n] << endl;


    return 0;
}


Measured memory_bytes: 43864