#include <bits/stdc++.h>
using namespace std;
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > p(n);
  multiset<int> st;
  for (int i = 0; i < n; ++i) {
    p[i].first = in();
    p[i].second = in();
    st.insert(p[i].second);
  }
  sort((p).begin(), (p).end());
  int l = 0;
  for (int i = 0; i < n; ++i) {
    if (l < p[i].first && l <= m) l++;
  }
  priority_queue<int> que;
  int j = n;
  for (int i = l; i >= 1; --i) {
    while (j > 0 && p[j - 1].first >= i) {
      que.push(p[j - 1].second);
      j--;
    }
    int x = que.top();
    que.pop();
    st.erase(st.find(x));
  }
  vector<int> hoge;
  for (int x : st) hoge.push_back(x);
  reverse((hoge).begin(), (hoge).end());
  int r = m + 1;
  for (int x : hoge) {
    cout << x << endl;
    if (x < r && r - 1 > l) r--;
  }
  cout << n - (l + (m - r + 1)) << endl;
  return 0;
}
