#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define sortV(v) v.begin(),v.end()
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
// DSU
/*
const int maxn=100009;
int arr[maxn];
int sz[maxn];
void init(){rep(i,maxn){arr[i]=i;sz[i]=1;}}
int root(int a){while(a!=arr[a]){arr[a]=arr[arr[a]];a=arr[a];}return a;}
int check(int a,int b){if(root(a)==root(b))return 1;return 0;}
int un(int a,int b)
{
  int roota=root(a);int rootb=root(b);
  if(sz[roota]>=sz[rootb]){sz[roota]+=sz[rootb];arr[rootb]=roota;}
  else {sz[rootb]+=sz[roota];arr[roota]=rootb;}
}
*/

//Dijkstra
/*
const int maxn=0x3f3f3f3f;
void dijkstra(int n,int dist[],vector<pi >adj[],int s)
{
  int visited[n+1];
  repre(i,0,n)
  {
    visited[i]=0;
    dist[i]=maxn;
  }
  dist[s]=0;
  priority_queue<pi ,vector<pi>,greater<pi> >p;
  p.push(mkp(0,s));
  while(p.empty()==false)
  {
    pi temp=p.top();
    p.pop();
    if(visited[temp.ss])continue;
    visited[temp.ss]=1;
    int u=temp.ss;
    rep(i,adj[u].size())
    {
      if(dist[u]+adj[u][i].ss<dist[adj[u][i].ff])
      {
        dist[adj[u][i].ff]=dist[u]+adj[u][i].ss;
        p.push(mkp(dist[adj[u][i].ff],adj[u][i].ff));
      }
    }
  }
}*/
int ans[100009];
int arr[100009];
int find(int a)
{
  if(a==0)return 0;
  while(a!=arr[a])
  {
    if(a==0)break;
    arr[a]=arr[arr[a]];
    a=arr[a];
  }
  return a;
}
bool cmp(const pi& a,const pi& b)
{
  if(a.ff==b.ff)
  {
    return a.ss>b.ss;
  }
  return a.ff>b.ff;
}
int32_t main()
{
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  fastio
  int n,m;
  cin>>n>>m;
  vector<pi >v;
  rep(i,n)
  {
    int day,prof;
    cin>>day>>prof;
    v.pb(mkp(prof,day));
  }
  repre(i,0,100008)arr[i]=i;
  sort(sortV(v),cmp);
  int res=0;
  rep(i,n)
  {
    int day=v[i].ss;
    int p=v[i].ff;
    int start=m-day;
    if(start<0)continue;
    for(int j=find(start);j>=0;j=find(j))
    {
      if(j==0 && ans[j]==0)
      {
        ans[j]=i+1;
        res+=p;
      }
      else if(j==0 && ans[j]!=0)break;
      if(arr[j]==j)
      {
        arr[j]=j-1;
        if(arr[j]<0)arr[j]=0;
        if(ans[j]==0)
        {
          ans[j]=i+1;
          res+=p;
          break;
        }
      }
    }
//  cout<<res<<endl;
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 3568