"use strict";
    
class PriorityQueue {
  constructor() {
    this.heap = [];
  }
 
  push(item) {
    let heap = this.heap;
    let i = heap.length++;
    let j;
 
    while(i) {
      j = Math.floor((i - 1) / 2);
      if(heap[j] <= item) break;
      heap[i] = heap[j]
      i = j;
    }
 
    heap[i] = item;
  }
 
  pop() {
    let heap = this.heap;
    let top = heap[0];
    let popped = heap.pop();
 
    let i = 0;
    let k = Math.floor(heap.length / 2);
    let j;
 
    while(i < k) {
      j = (i * 2) + 1;
      if(heap[j+1] < heap[j]) ++j;
 
      if(popped <= heap[j]) break;
 
      heap[i] = heap[j];
 
      i = j;
    }
 
    if(heap.length) {
      heap[i] = popped;
    }
 
    return top;
  }
 
  size() {
    return this.heap.length;
  }
 
  top() {
    return this.heap[0];
  }
}

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);
    
    let AB = arg.slice(1, N + 1).map(n=>n.split(" ").map(l=>parseInt(l)));
    AB.push([1e9, 0]);
    AB.sort((a,b)=>a[0]-b[0]);
    
    let answer = 0;
    let j = 0;
    
    let pq = new PriorityQueue();
    
    for(let i=1; i<=M; i++) {
        while(AB[j][0] <= i) {
            pq.push(-AB[j][1]);
            j++;
        }
        
        if(pq.size() > 0) {
            answer += pq.pop();
        }
    }
    
    console.log(0 - answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
