"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);
    
    const AB = arg.slice(1, N + 1).map(n=>n.split(" ").map(l=>parseInt(l)));
    
    let tasks = [];
    
    for(let i in AB) {
        tasks.push({reward: AB[i][1], day: AB[i][0]});
    }
    
    // 二重ソート（まず報酬順、次に残り日数でソート）
    tasks.sort((a,b)=> {
        if(a.reward < b.reward) return 1
        if(a.reward > b.reward) return -1
        if(a.day < b.day) return 1
        if(a.day > b.day) return -1

        return 0
    })
    
    let answer = 0;
  
  	if(M === 1) {
        console.log(answer);
        return;
    }
  
    for(let i=0; i<M; i++) {
        let todaysTask = tasks[i];
        let j = i;

        while(todaysTask.day + j > M + 1) {
            todaysTask = tasks[j + 1];
            j++;
            
            if(j === N) break;
        }
        
        answer += tasks[i].reward;
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));