#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
int arr[100005], brr[100005];
std::priority_queue <int> v[100005];
int main ()
{
	int n, m, tot=0;
	scanf("%d\n", &n, &m);
	for (int i=1; i<=n; i++)
	{
		scanf("%d %d", &arr[i], &brr[i]);
		v[arr[i]].push(brr[i]);
	}
	int k,r=1;
	for (int i=m; i>=1; i--)
	{   k=r;
		for (int j=1; j<=k; j++)
		{
			if (v[i].empty()) {r=k-j+1; break;
			}
			else{
				printf("%d\n", tot);
				tot+=v[i].top();
				v[i].pop();
			}
		}
	}
	printf("%d\n", tot);
}