#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
template <class T>
int upb(V<T> &v, const T &x) { return upper_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
//@docs Docs/Dijkstra.md
template <class T>
struct Dijkstra {
    int n;
    vector<vector<pair<T, int>>> G;
    Dijkstra(int n) : n(n), G(n) {}
    void addedge(const int &u, const int &v, const T &c) { G[u].emplace_back(v, c); }
    vector<T> dijkstra(const int &st, int en) {
        priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q;
        vector<T> d(n, INF);
        for (int i = st; i <= en; i++) {
            d[i] = 0;
            q.emplace(0, i);
        }
        while (!q.empty()) {
            int v = q.top().second;
            T dd = q.top().first;
            q.pop();
            if (d[v] < dd) continue;
            for (auto &e : G[v]) {
                if (d[e.first] > d[v] + e.second) {
                    d[e.first] = d[v] + e.second;
                    q.emplace(d[e.first], e.first);
                }
            }
        }
        return d;
    }
};
//Range Update Point Get

struct T {
    ll a;
    T() {}
    T(ll x) : a(x) {}
    inline static T id() {
        return T{INF};
    }
    inline static T f(const T &x, const T &y) {
        return min(x.a, y.a);
    }
    inline static T g(const T &x, const T &y) { return min(x.a, y.a); }
};
template <class T>
struct Segtree {
    vector<T> dat;
    int n;
    T e;
    Segtree(int n_) {
        n = 1;
        while (n < n_) {
            n <<= 1;
        }
        dat.resize(2 * n, T::id());
    }
    void upd(const int &a, const int &b, const T &x, int k, int l, int r) {
        if (b <= l || r <= a) {
            return;
        }
        if (a <= l && r <= b) {
            dat[k] = T::g(dat[k], x);
            return;
        }
        upd(a, b, x, k << 1, l, (l + r) >> 1);
        upd(a, b, x, k << 1 | 1, (l + r) >> 1, r);
    }
    inline void upd(const int &a, const int &b, const T &x) {
        if (a >= b) {
            return;
        }
        upd(a, b, x, 1, 0, n);
    }
    T get(int k) {
        k += n;
        T res = dat[k];
        k >>= 1;
        while (k > 0) {
            res = T::f(res, dat[k]);
            k >>= 1;
        }
        return res;
    }
};

//////////////////////////////////////////////INSERT ABOVE HERE
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    V<int> a(h), b(h);
    V<int> l(h + w), r(h + w, -1);
    for (int i = 0; i < h; i++) {
        cin >> a[i] >> b[i];
        --a[i];
        --b[i];
        l[i] = i;
    }
    set<P> st;
    Dijkstra<ll> di(h + w);
    for (int i = 0; i < w; i++) {
        if (a[0] <= i && i <= b[0]) continue;
        st.insert(P(i, h + i));
        l[h + i] = 0;
    }
    for (int i = 1; i < h; i++) {
        auto il = st.lower_bound(P(a[i], -1)), ir = st.lower_bound(P(b[i] + 1, -1));
        for (auto it = il; it != ir; it++) {
            ll t = (*it).se;
            if ((*it).se >= h) t = 0;
            if (b[i] < w - 1) {
                //  dump((*it).se, i);
                di.addedge((*it).se, i, abs((*it).fi - (b[i] + 1)) + i - t);
            }
            r[(*it).se] = i;
        }
        st.erase(il, ir);
        if (b[i] < w - 1) {
            st.insert(P(b[i] + 1, i));
        }
    }
    for (auto it : st) {
        r[it.se] = h;
    }
    V<ll> d = di.dijkstra(h, h + w - 1);
    /* print(d);
    print(r);*/
    Segtree<T> seg(h + 10);
    for (int i = 0; i < h + w; i++) {
        if (r[i] != -1 && d[i] != INF) {
            seg.upd(l[i], r[i] + 1, d[i] - l[i]);
        }
    }
    for (int i = 1; i <= h; i++) {
        ll s = seg.get(i).a;
        if (s == INF) {
            cout << -1 << newl;
        } else {
            cout << i + s << newl;
        }
    }
}

Measured memory_bytes: 37240