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

#ifdef natural_selection
#include "../libra/misc/dbg.h"
#else
#define debug(...)
#define endl "\n"
#endif

template <typename Info, typename Tag>
class SegTreeChan
{
public:
    int n;
    vector<Info> infos;
    vector<Tag> tags;

    template<typename O>
    void Recurse(int lb, int rb, bool update, O op)
    {
        auto rec = [&](int v, int l, int r, auto &&rec) -> void
        {
            Propagate(v, l, r);

            if(l > r)
                return;
            
            if(lb <= l and r <= rb)
            {
                op(v, l, r);
                return;
            }
            
            int m = (l + r)/2;
            
            if(m >= lb)
                rec(2 * v, l, m, rec);
            else if(update)
                Propagate(2 * v, l, m);

            if(m + 1 <= rb)
                rec(2 * v + 1, m + 1, r, rec);
            else if(update)
                Propagate(2 * v + 1, m + 1, r);
            
            if(update)
                infos[v] = infos[2 * v].Unite(infos[2 * v + 1]);
        };
        rec(1, 0, n - 1, rec);
    };

    SegTreeChan() : SegTreeChan(0) {};
    SegTreeChan(int n) : SegTreeChan(vector<Info> (n)) {};
    SegTreeChan(const vector<Info> &a) : 
    n((int)a.size()), infos(4 * n + 5), tags(4 * n + 5)
    {
        auto build = [&](int v, int l, int r, auto &&build) -> void
        {
            if(l > r)
                return;
            if(l == r)
            {
                infos[v] = Info(a[l]);
                return;
            }
            int m = (l + r)/2;
            build(v * 2, l, m, build);
            build(v * 2 + 1, m + 1, r, build);
            infos[v] = infos[v * 2].Unite(infos[v * 2 + 1]);
        };
        build(1, 0, n - 1, build);
    };

    void Propagate(int v, int l, int r)
    {
        if(tags[v].Empty())
            return;
        tags[v].ApplyTo(infos[v], l, r);
        if(l != r)
        {
            tags[v].ApplyTo(tags[2 * v]);
            tags[v].ApplyTo(tags[2 * v  + 1]);
        }
        tags[v] = Tag();
    }

    void Modify(int lb, int rb, const Tag &tag)
    {
        Recurse(lb, rb, true, [&](int v, int l, int r)
        {
            tag.ApplyTo(tags[v]);
            Propagate(v, l, r);
        });
    }
    void Set(int p, const Info &info)
    {
        Recurse(p, p, true, [&](int v, int l, int r)
        {
            infos[v] = info;
        });
    }
    void Add(int p, const Info &info)
    {
        Recurse(p, p, true, [&](int v, int l, int r)
        {
            infos[v] = infos[v].Unite(info);
            Propagate(v, l, r);
        });
    }
    Info Query(int lb, int rb)
    {
        Info res = Info();
        Recurse(lb, rb, false, [&](int v, int l, int r)
        {
            res = res.Unite(infos[v]);
        });
        return res;
    }
    Info Get(int p)
    {
        Info res = Info();
        Recurse(p, p, false, [&](int v, int l, int r)
        {
            res = infos[v];
        });
        return res;
    }
};

const int64_t inf = numeric_limits<int64_t>::max();

class InfoChan
{
public:
    pair<int64_t, int> mn;

    InfoChan() : mn(make_pair(inf, -1)) {};     //if second element is -1, it means no element
    InfoChan(int i, int64_t x) : mn(x, i) {};

    InfoChan Unite(InfoChan b) const 
    {
        InfoChan res;
        if(mn.second == -1)
            res.mn = b.mn;
        else if(b.mn.second == -1)
            res.mn = mn;
        else
            res.mn = min(mn, b.mn);
        return res;
    }
    static InfoChan GetDefault([[maybe_unused]] int l, [[maybe_unused]] int r)
    {
        return InfoChan();
    }
};
class TagChan
{
public:
    int64_t paint;

    TagChan() : paint(inf) {};
    TagChan(int x) : paint(x) {};

    bool ApplyTo(InfoChan &a, [[maybe_unused]] int l, [[maybe_unused]] int r) const
    {
        if(a.mn.second != -1)
            a.mn.first = min(a.mn.first, paint);
        return true;
    }
    void ApplyTo(TagChan &t) const
    {
        t.paint = min(t.paint, paint);
    }
    bool Empty() const
    {
        return paint == inf;
    }
};


int32_t main()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL);

    int n, m;
    cin >> n >> m;

    vector<vector<array<int, 3>>> adj(n);
    for(int i = 0; i < m; i ++)
    {
        int u, l, r, c;
        cin >> u >> l >> r >> c;
        -- u, -- l, -- r, c;
        adj[u].push_back({l, r, c});
    }

    vector<InfoChan> a(n);
    for(int i = 0; i < n; i ++)
        a[i].mn = {(i == 0 ? 0 : inf), i};

    SegTreeChan<InfoChan, TagChan> rq(a);

    vector<int64_t> dis(n);

    for(int i = 0; i < n; i ++)
    {
        auto [d, u] = rq.Query(0, n - 1).mn;
        dis[u] = d;

        assert(u != -1);

        for(auto [l, r, c] : adj[u])
            rq.Modify(l, r, TagChan(d + c));

        rq.Set(u, InfoChan());
    }

    for(int u = 0; u < n; u ++)
        cout << dis[u] << " ";
    cout << endl;
}