class NormalInput {
  input: string[];
  pointer: number;
  constructor(raw: string) {
    this.input = raw.split(/ |\n/);
    this.pointer = 0;
  }
  int(): number {
    const ret = parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  }
  str(): string {
    const ret = this.input[this.pointer];
    this.pointer++;
    return ret;
  }
  strs(length: number): string[] {
    let ret: string[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.str());
    }
    return ret;
  }
  ints(length: number): number[] {
    let ret: number[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.int());
    }
    return ret;
  }
}
function divInt(a: number, b: number) {
  return Math.floor(a / b);
}
class Heap<T> {
  data: T[];
  compare: (a: T, b: T) => number;
  constructor(data: T[], compare: (a: T, b: T) => number) {
    data.sort(compare);
    this.data = data;
    this.compare = compare;
  }
  push(a: T): void {
    this.data.push(a);
    this._fixUp(this.data.length - 1);
  }
  _fixUp(pos: number): void {
    if (pos === 0) return;
    const parent = divInt(pos - 1, 2);
    if (this.compare(this.data[parent], this.data[pos]) < 0) {
      this._swap(parent, pos);
      this._fixUp(parent);
    }
  }
  _fixDown(pos: number): void {
    const leftSwapped =
      pos * 2 + 1 < this.data.length &&
      this.compare(this.data[pos], this.data[pos * 2 + 1]) < 0;
    const rightSwapped =
      pos * 2 + 2 < this.data.length &&
      this.compare(this.data[pos], this.data[pos * 2 + 2]) < 0;
    if (leftSwapped) {
      if (rightSwapped) {
        if (this.compare(this.data[pos * 2 + 1], this.data[pos * 2 + 2]) < 0) {
          this._swap(pos * 2 + 2, pos);
          this._fixDown(pos * 2 + 2);
        } else {
          this._swap(pos * 2 + 1, pos);
          this._fixDown(pos * 2 + 1);
        }
      } else {
        this._swap(pos * 2 + 1, pos);
        this._fixDown(pos * 2 + 1);
      }
    } else {
      if (rightSwapped) {
        this._swap(pos * 2 + 2, pos);
        this._fixDown(pos * 2 + 2);
      }
    }
  }
  _swap(a: number, b: number): void {
    [this.data[a], this.data[b]] = [this.data[b], this.data[a]];
  }
  /**
   * get maximum value.
   */
  pop(): T {
    if (this.data.length == 0) throw "Heap is empty!";
    const top = this.data[0];
    if (this.data.length > 1) {
      this.data[0] = this.data.pop();
      this._fixDown(0);
    }else{
      this.data.pop();
    }
    return top;
  }
  top(): T | void {
    if (this.data.length == 0) return undefined;
    return this.data[0];
  }
  empty(): boolean {
    return this.data.length == 0;
  }
  _debug(): void {
    console.log("Heap", JSON.stringify(this));
  }
}
function Main(_: NormalInput) {
  const [N, M] = _.ints(2);
  const AB = _.ints(2 * N);
  let A = AB.filter((_, i) => i % 2 == 0);
  let B = AB.filter((_, i) => i % 2 == 1);
  const Job = A.map((_, i) => [A[i], B[i]] as [number, number]);
  Job.sort((x, y) => y[0] - x[0]);
  const candidate = new Heap<[number, number]>([], (x, y) => x[1] - y[1]);
  let ans = 0;
  for (let day = 1; day <= M; day++) {
    while (Job.length > 0 && Job[Job.length - 1][0] <= day) {
      candidate.push(Job.pop());
    }
    if (!candidate.empty()) {
      // console.log("pop", candidate.top());
      ans += candidate.pop()[1];
    }
  }
  console.log(ans);
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 65904