jiahuimbzuai/CoQuIR huggingface dataset:
//  [java]
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        System.out.println( solve(A, B) );
    }

    private static int solve(int A, int B) {
        int sum = A + B;
        int minus = A - B;
        int mul = A * B;

        return Math.max(Math.max(sum, minus),mul);
    }
}
//  [cpp]
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>

#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;


int main(){
	int A, B;
	cin >> A >> B;

	int max = MAX(-1000000, A + B);
	max = MAX(max, A - B);
	max = MAX(max, A * B);
	

	cout << max << endl;
}
//  [cpp]
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;


    int x[3] = {a+b, a-b, a*b};

    cout << max(max(x[0],x[1]),x[2]) << endl;


    return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
 
  int a,b;
  cin>>a>>b;
  int ans=a+b;
  int tmp=a-b;
  if(ans<tmp)ans=tmp;
  tmp=a*b;
  if(ans<tmp)ans=tmp;
  cout<<ans<<endl;
  return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int A, B;

    scanf("%d%d", &A, &B);

    int max = A + B;

    if(max < A - B){
        max = A - B;
    }

    if(max < A * B){
        max = A * B;
    }

    printf("%d\n", max);

    return 0;
}
//  [c]
#include <stdio.h>

int main()
{
	int A, B;
	scanf("%d %d", &A, &B);
	if (A + B >= A - B && A + B >= A * B) printf("%d\n", A + B);
	else if (A - B >= A + B && A - B >= A * B) printf("%d\n", A - B);
	else printf("%d\n", A * B);
	fflush(stdout);
	return 0;
}
//  [c]
#include <stdio.h>
int main ()
{
	int a,b,c,d,e;
	scanf("%d %d",&a,&b);
	c=a+b;
	d=a-b;
	e=a*b;
	if(c>=d&&c>=e)
	printf("%d\n",c);
    else if(d>=c&&d>=e)
 	printf("%d\n",d);
 	else if(e>=c&&e>=d)
 	printf("%d\n",e);
	
	return 0;

}
//  [javascript]
var main = function(input) {
  input = input.split(' ').map(x=>parseInt(x));
  var a = input[0];
  var b = input[1];
  var max　= a+b;
  if(max<a-b){
    max = a-b;
  }
  if(max<a*b){
    max=a*b;
  }
  if(max === -0){
    max = 0;
  }
  console.log(max);

    return 0; 
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const A = parseInt(args[0][0], 10)
	const B = parseInt(args[0][1], 10)
	console.log(Math.max(A + B, A - B, A * B) + 0)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [javascript]
function main(input) {
    var a = input[0].split(" ")[0]-0;
    var b = input[0].split(" ")[1]-0;
    console.log(~~Math.max(a+b, a-b, a*b));
    
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))
//  [go]
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for A - Add Sub Mul
	var A, B float64
	fmt.Scanf("%f %f", &A, &B)
	fmt.Println(int(math.Max(A+B, math.Max(A-B, A*B))))
}
//  [go]
package main

import "fmt"

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	fmt.Println(max(max(a+b, a-b), a*b))
}
//  [ruby]
a,b=gets.split.map &:to_i;p [a+b,a-b,a*b].max
//  [ruby]
a=gets.split.map(&:to_i)
p [a.inject(:+),a.inject(:*),a.inject(:-)].max
//  [ruby]
a,b = gets.chomp.split(' ').map(&:to_i)
puts [a+b,a-b,a*b].sort.last
//  [rust]
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:isize,
    b:isize,
    }
    println!("{}",max(a+b,max(a-b,a*b)))
}
//  [rust]
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        a: isize, b: isize, 
    }
    println!("{}", [a+b, a-b, a*b].iter().max().unwrap());
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}
//  [rust]
use std::io::*;
use std::str::FromStr;
use std::cmp::max;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    println!("{}", max(max(a+b, a-b), a*b));

}
//  [swift]
#if os(Linux)
    import Glibc
#else
    import Foundation
    import Darwin
#endif

#if swift(>=4.0)
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

prefix operator *
prefix func * <T> (a: [T]) -> (T, T) { return (a[0], a[1]) }
prefix func * <T> (a: [T]) -> (T, T, T) { return (a[0], a[1], a[2]) }
#else
func readInts() -> [Int] {
    return readLine()!.split(" ").map { Int($0)! }
}

prefix operator * {}
prefix func * <T> (a: [T]) -> (T, T) { return (a[0], a[1]) }
prefix func * <T> (a: [T]) -> (T, T, T) { return (a[0], a[1], a[2]) }

extension String: CollectionType {}
#endif


let (A, B) = *readInts()

print(max(A + B, A - B, A * B))
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [A, B] = input[0].map(Number);

  return Math.max(A + B, A - B, A * B) + 0;
};

console.log(main(read()));
//  [typescript]
"use strict";

new Promise(resolve => {
  resolve(require("fs").readFileSync("/dev/stdin", "utf8").split(/\s/));
}).then(input => {
  const [A, B] = input.map(x => Number(x));
  const N = [A + B, A - B, A * B];
  const temp = Math.max(...N);
  const ans = temp === -0 ? 0 : temp;
  console.log(ans);
});
//  [typescript]
import * as fs from 'fs';

const input = (fs.readFileSync('/dev/stdin', 'utf8') as string).split('\n');

const [a, b] = input[0].split(' ').map((x) => +x);
const t = Math.max(a - b, a + b, a * b);

console.log(t === -0 ? 0 : t);
//  [python]
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()
import fractions
gcd=fractions.gcd
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0
k,x=LI()
if k*500>=x:
    ans='Yes'
else:
    ans='No'

print(ans)
//  [python]
from sys import stdin
import numpy as np


# noinspection PyShadowingBuiltinsInspection

def main():
    K, X = [int(x) for x in input().split()]
    if 500 * K >= X:
        print("Yes")
    else:
        print("No")

    return


if __name__ == "__main__":
    main()
//  [python]
import numpy as np

def main():
    K, X = map(int, input().split())
    if (500 * K) >= X:
        print("Yes")
    else:
        print("No")
    return 0

if __name__ == '__main__':
    main()
//  [java]
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

class Main{
    public static void main(String[] args) throws IOException {
        int[] inputs = receiveIntArray(Delimiter.SPACE);
        int num = inputs[0];
        int goal = inputs[1];
        
        println(num * 500 >= goal ? "Yes" : "No");
        flush();
    }



    // 入出力関連
    static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static final PrintWriter pw = new PrintWriter(System.out);
    enum Delimiter {
        NONE(""),
        SPACE(" "),
        DOT("\\."),
        COMMA(",");

        private String regex;
        private Delimiter(String regex) {
            this.regex = regex;
        }
        public String getRegex() { return regex; }
    }

    static String receive() throws IOException { return br.readLine(); }
    static int receiveInt() throws IOException { return Integer.parseInt(br.readLine()); }
    static char receiveChar() throws IOException { return  br.readLine().charAt(0); }
    static char[] receiveCharArray() throws IOException { return  br.readLine().toCharArray(); }
    static int[] receiveIntArray(Delimiter delimiter) throws IOException {
        return Stream.of(br.readLine().split(delimiter.getRegex())).mapToInt(Integer::parseInt).toArray();
    }
    static String[] receiveStringArray(Delimiter delimiter) throws IOException {
        return Stream.of(br.readLine().split(delimiter.getRegex())).toArray(String[]::new);
    }

    static void print(Object obj) { pw.print(obj); }
    static void println(Object obj) { pw.println(obj); }
    static void flush() { pw.flush(); }
}
//  [java]
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int K = sc.nextInt();
        int X = sc.nextInt();

        if(500*K >= X)
        {
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
        // 出力
        //System.out.println();
    }
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

int main(){
  int n,x;cin >> n >> x; 
  if(500*n>=x){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}
//  [c]
#include<stdio.h>
int main(void){
	int k,x;
	scanf("%d %d",&k,&x);
	if(k*500>=x){
		printf("Yes");	
	}else{
		printf("No");	
	}
}
//  [c]
#include <stdio.h>
int main()
{
  int k,x;
	scanf("%d %d",&k,&x);
  if(500*k < x)	printf("No");
  else printf("Yes");
  return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a, b;
    
    scanf("%d%d", &a, &b);
    
    if (500*a>=b) {
        printf("Yes");
    } else {
        printf("No");
    }

    return 0;
}
//  [javascript]
"use strict"
function Main(input) {
  input = input.trim().split(' ').map(Number);
  const K = input[0];
  const X = input[1];

  if(K * 500 >= X) {
    console.log('Yes')
    return;
  }
  console.log('No');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
Main(myin());
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));default:return i;}}
function Main(input) {
  input = myconv(input,4);
  if(input[0] * 500 >= input[1]){
     myout("Yes");
     }else{
     myout("No");
     }
}
//  [javascript]
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var k = o.a();
  var x = o.a();
  return k*500>=x?"Yes":"No";
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	k, x := intScanner(), intScanner()
	if k*500 >= x {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
//  [go]
package main

import (
	"fmt"
)

func main() {
  var k, x int
  fmt.Scanf("%d %d", &k, &x)
  ans := "No"
  if 500 * k >= x {
    ans = "Yes"
  }
  fmt.Printf("%s\n", ans)
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var K, X int
	fmt.Scanf("%d %d", &K, &X)

	if X <= 500*K {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
//  [ruby]
k, x = gets.split.map(&:to_i)
puts 500 * k >= x ? "Yes" : "No"
//  [ruby]
k,x = gets.chomp.split(' ').map(&:to_i)
if k * 500 >= x
  puts "Yes"
else
  puts "No"
end
//  [ruby]
k, x = gets.split.map(&:to_i)

puts 500*k >= x ? "Yes" : "No"
//  [rust]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {k: usize, x: usize};

    if 500 * k >= x {
        println!("Yes")
    } else {
        println!("No")
    }
}
//  [swift]
import Foundation
 
let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")
 
let K = Int(split[0])!
let X = Int(split[1])!

if (500*K>=X){
    print("Yes")
}else{
    print("No")
}
//  [swift]
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}
let k = arr[0]
let x = arr[1]

if( 500*k >= x ) {
  print("Yes")
} else {
  print("No")
}
//  [swift]
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let kx = readInts()
    if kx[0] * 500 >= kx[1] {
        print("Yes")
    } else {
        print("No")
    }
}

main()
//  [typescript]
import * as fs from 'fs';
//in
// 2 900
//out
// Yes
function main(inp: string) {
    const [k, x] = inp.split(' ').map(Number);
    if (k*500>=x) {
        console.log('Yes');
    } else {
        console.log('No');
    }
}

main(fs.readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
{
  const main = (
    input: string
  ): void | string | number | string[] | number[] => {
    const r = _reader(input)
    const [K, X] = r.nn()

    return K * 500 >= X ? 'Yes' : 'No'
  }

  const _reader = (str: string, i = 0) => {
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')
    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map(v => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  const _getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const _res = main(_getInput())

  if (typeof _res === 'number' || typeof _res === 'string') console.log(_res)
  if (typeof _res === 'object') console.log(_res.join(' '))
}
//  [python]
x,a,b = map(int,input().split())
if abs(x-a)>abs(x-b):
    print("B")
else:
    print("A")
//  [python]


import numpy as np

x,a,b=map(int,input().split())
a=abs(a-x)
b=abs(b-x)

if(a<b):
    print("A")
else:
    print("B")
//  [python]
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
from fractions  import gcd

input=sys.stdin.readline
x,a,b=map(int,input().split())
if abs(x-a)<abs(x-b):
    print("A")
else:
    print("B")
//  [java]
import java.util.Scanner;

public class Main {

    private final static Scanner sc = new Scanner(System.in);

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        int x = nextInt();
        int a = nextInt();
        int b = nextInt();

        int ax = Math.abs(x - a);
        int bx = Math.abs(x - b);

        if (ax < bx) {
            out("A");
        } else {
            out("B");
        }
    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt() {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString() {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt();
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }
}
//  [java]
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int x = Math.abs(b-a);
    int y = Math.abs(c-a);
    System.out.println(x < y ? "A" : "B");
  }
}
//  [java]
import java.util.Scanner;

public class Main {
    private static Scanner sc;

    public Main() {
    }

    public static void main(String[] args) {
        sc = new Scanner(System.in);
        new Main().solve();

    }

    private void solve() {
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (Math.abs(x - a) < Math.abs(x - b)) {
            System.out.println("A");
        } else {
            System.out.println("B");
        }
    }
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int x,a,b;cin>>x>>a>>b;
  int ax=abs(a-x);
  int bx=abs(b-x);
  string ans="A";
  if(ax>bx)ans="B";
  cout(ans);
  
  return 0;
}
//  [cpp]
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()

using namespace std;

int main() {
  int x, a, b;
  cin >> x >> a >> b;

  puts(abs(a - x) <= abs(b - x) ? "A" : "B");

  return 0;
}
//  [cpp]
#include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;

const int MAXN=500005;
const int NAX=1005;
const long long  MOD=(long long)(998244353);

Int N,M,K;
Int X,Y,Z;
Int H,W;

Int perform(Int x){
    return (x*(x+1))/2LL;
}
vector<Int> A;
vector<int> adj[MAXN];
using D=long double;

bool inRange(Int a,Int b){
    return a*b<=0;
}

long long C[NAX][NAX];
const D pi=3.14159265359;


long long ModExpo(long long x,unsigned long long y,long long M){
    Int ans=1;
    ans=(long long)ans;
    
    while(y>0){
        if(y&1) ans=((ans%M)*(x%M))%M;
        y>>=1LL;
        x=((x%M)*(x%M))%M;
    }
    return ans%M;
}
long long fac[MAXN];
void fillFac(){
    fac[0]=1;
    for(int i=1;i<MAXN;++i){
        fac[i]=((fac[i-1]%MOD)*(i%MOD))%MOD;
    }
}

long long ModInv(long long x){
    return ModExpo(x,MOD-2,MOD);
}

long long FermatLast(long long n,long long r){
    if(r>n) return 0;
    if(!r) return 1;
    return (fac[n] * ModInv(fac[r]) % MOD * ModInv(fac[n - r]) % MOD) % MOD;
}

Int performMod(Int x){
    Int y=((x%MOD)*((x+1)%MOD))%MOD;
    return (y*ModInv(2))%MOD;
}

Int madd(Int x,Int y){
    return (x+y)%MOD;
}

Int mmul(Int x,Int y){
    return ((x%MOD)*(y%MOD))%MOD;
}


bool isMSB(int bit,Int x){
    return (int)(floor(log2l(x)))==bit;
}
bool VIS[MAXN];
void dfs(int u){
    VIS[u]=true;
        for(auto &v:adj[u]){
            if(!VIS[v]){
                dfs(v);
            }
        }
}
int main()
{
    cin>>N>>X>>Y;
    cout<<(abs(N-X)>abs(N-Y) ? "B":"A")<<"\n";
            
}
//  [c]
#include<stdio.h>

int main(){
	int x,a,b;
	scanf("%d %d %d", &x,&a,&b);
	int xa,xb;
	if(x>a){
		xa=x-a;
	}
	else xa=a-x;
	if(x>b){
		xb=x-b;
	}
	else xb=b-x;
	if(xa<xb){
		printf("A");
	}
	else printf("B");
	return 0;
}
//  [c]
#include <stdio.h>

int main(void)
{
        int a,b,A,B,x;
        scanf("%d%d%d",&x,&a,&b);
        A=a-x;B=b-x;
        if(A<0)A=-A;
        if(B<0)B=-B;
        if(A<B)printf("A\n");
        else printf("B\n");
        return 0;
}
//  [c]
#include <stdio.h>

int main() {
	int X, A, B;
	scanf("%d %d %d", &X, &A, &B);
	int T, Y;
	T = A - X;
	Y = B - X;
	if ( T < 0 ) {
		T *= -1;
    }
	if ( Y < 0 ) {
		Y *= -1;
	}
	if (T < Y) {
		printf("A");
	} else {
		printf("B");
	}
	return 0;
}
//  [javascript]
function main(input){
    var tmp = input.split(" ");
    var x = Number(tmp[0]);
    var a = Number(tmp[1]);
    var b = Number(tmp[2]);

    if(Math.abs(x-a) < Math.abs(x-b))
        console.log("A");
    else
        console.log("B");
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
  const inputs = input.split(" ");
  const x = parseInt(inputs[0], 10);
  const a = parseInt(inputs[1], 10);
  const b = parseInt(inputs[2], 10);
  
  const distA = Math.abs(x - a);
  const distB = Math.abs(x - b);
  if (distA < distB) {
    console.log('A');
  } else {
    console.log('B');
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {
    var line = input[0].split(' ');
    var x = parseInt(line[0]);
    var a = parseInt(line[1]);
    var b = parseInt(line[2]);

    if (Math.abs(x - a) <= Math.abs(x - b)) {
        console.log('A');
    }
    else {
        console.log('B');
    }
}
//  [go]
package main

// Solution for https://atcoder.jp/contests/abc071/tasks/abc071_a

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var x, a, b int
	con.Scan(&x, &a, &b)
	xa := x - a
	if xa < 0 {
		xa = -xa
	}
	xb := x - b
	if xb < 0 {
		xb = -xb
	}
	if xa < xb {
		con.Println("A")
	} else {
		con.Println("B")
	}
	return nil
}
//  [go]
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for A - Meal Delivery
	var x, a, b int
	fmt.Scanf("%d %d %d", &x, &a, &b)

	if math.Abs(float64(x-a)) > math.Abs(float64(x-b)) {
		fmt.Printf("B")
	} else {
		fmt.Printf("A")
	}
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	x := nextInt()
	a := nextInt()
	b := nextInt()

	da := x - a
	if da < 0 {
		da *= -1
	}
	db := x - b
	if db < 0 {
		db *= -1
	}

	if da < db {
		fmt.Println("A")
	} else {
		fmt.Println("B")
	}
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}
//  [ruby]
x,a,b=gets.split.map(&:to_i)
puts (x-a).abs<(x-b).abs ? ?A : ?B
//  [ruby]
# Your code here!

x,a,b=gets().chomp().split().map(&:to_i)
if (x-a).abs<(x-b).abs
    puts("A")
elsif (x-a).abs>(x-b).abs
    puts("B")
end
//  [ruby]
x,a,b = gets.chop.split.map(&:to_i)
if (a-x).abs < (b-x).abs then
    puts 'A'
else
    puts 'B'
end
//  [rust]
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        (x, a, b): (i32, i32, i32)
    }
    if (x-a).abs() < (x-b).abs() {
        println!("A");
    } else {
        println!("B");
    }
}
//  [rust]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (x, a, b) = get!(i32, i32, i32);
    println!("{}", if (x - a).abs() < (x - b).abs() { "A" } else { "B" });
}
//  [rust]
use proconio::input;

fn main(){
    input!{
        x:i32,
        a:i32,
        b:i32
    }
    let da = x-a;
    let db = x-b;
    if da.abs() < db.abs(){
        println!("A")
    }else{
        println!("B")
    }


}
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [x, a, b] = input[0].map(Number);

  return Math.abs(x - a) < Math.abs(x - b) ? "A" : "B";
};

console.log(main(read()));
//  [typescript]
"use strict";

main(require("fs").readFileSync("/dev/stdin", "utf8"));

function main(input) {
  const [x, a, b] = input.split(" ").map(Number);

  const ans = Math.abs(x - a) < Math.abs(x - b) ? 'A' : 'B';
  console.log(ans);
}
//  [typescript]
import * as fs from 'fs';

const [x, a, b]: number[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split(' ').map(Number);
if (Math.abs(x - a) < Math.abs(x - b)) {
    console.log('A');
} else {
    console.log('B');
}
//  [python]
import sys

input = sys.stdin.readline
N, M = map(int, input().split())

import bisect

ABs = [[] for _ in range(M + 1)]
for i in range(N):
    A, B = map(int, input().split())
    if A <= M:
        ABs[A].append(B)
ABs[0].sort()

As = 0
for i in range(M + 1):
    if i > 0:
        for b in ABs[i]:
            bisect.insort_left(ABs[0], b)
    if len(ABs[0]) > 0:
        As += ABs[0].pop()
print(As)
//  [python]
import heapq

def main():
    [N, M] = [int(number) for number in input().split()]
    part_times = []
    for i in range(N):
        job= [int(number) for number in input().split()]
        part_times.append(job)
    part_times = [part_time for part_time in sorted(part_times, key = lambda x: x[0])] #if part_time[0] <= M]
    money = 0
    hp = []
    for day in range(M):
        while part_times != [] and part_times[0][0] <= day + 1:
            part_time = part_times[0]
            heapq.heappush(hp, - part_time[1])
            part_times.pop(0)
        if hp != []:
            money -= heapq.heappop(hp)

    print(money)

if __name__ == '__main__':
    main()
//  [python]
import sys 
from bisect import insort
 
input = sys.stdin.readline

def main():
    N,M = map(int,input().split())
    jobs = [[] for _ in range(M)]
    
    for _ in range(N):
        A,B = map(int,input().split())
        if A<=M:
            jobs[M-A].append(B)
            
    job_candidate = []
    reward = 0
    
    for i in range(M-1,-1,-1):
        for x in jobs[i]:
            insort(job_candidate,x)
        if job_candidate:
            reward += job_candidate.pop(-1)
            
    print(reward)
            
    
    
if __name__ == "__main__":
    main()
//  [java]
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int M = nextInt();

		int[][] AB = new int[N][2];
		for(int i=0;i<N;i++) {
			AB[i] = nextIntArray(2);
		}
		Arrays.sort(AB,(a1,a2)->Integer.compare(a2[1],a1[1]));
		Arrays.sort(AB,(a1,a2)->Integer.compare(a1[0],a2[0]));

		List<Integer> list = new ArrayList<Integer>(N);
		long sum = 0;
		int AB_i = 0;
		for(int l=1;l<=M;l++) {
			int Search_l = -1;
			while(AB_i<N&&AB[AB_i][0]==l) {
				int Insert_i = Search(list ,AB[AB_i][1],Search_l);
				if(M<Insert_i)break;// 候補外となるため挿入する必要なし
				list.add(Insert_i,AB[AB_i][1]);
				AB_i++;
			}

			if(list.size()>0) {
				sum+=list.get(0);
				list.remove(0);
			}
		}

		out.println(sum);
	}

	//二部探索
	static int Search(List<Integer> list, int k, int Search_l) {
		int l = Search_l;
		int r = list.size();
		while(r - l > 1) {
			int mid = (r + l) / 2;
			if(list.get(mid) <= k) r = mid;
			else l = mid;
		}
		return r;
	}


	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}
}
//  [java]
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int M = nextInt();

		int[][] AB = new int[N][2];
		for(int i=0;i<N;i++) {
			AB[i] = nextIntArray(2);
		}
		Arrays.sort(AB,(a1,a2)->Integer.compare(a2[1],a1[1]));
		Arrays.sort(AB,(a1,a2)->Integer.compare(a1[0],a2[0]));

		List<Integer> list = new ArrayList<Integer>();
		long sum = 0;
		int AB_i = 0;
		for(int l=1;l<=M;l++) {
			int Search_l = -1;
			while(AB_i<N&&AB[AB_i][0]==l) {
				int Insert_i = Search(list ,AB[AB_i][1],Search_l);
				if(M<Insert_i)break;// 候補外となるため挿入する必要なし
				list.add(Insert_i,AB[AB_i][1]);
				AB_i++;
			}

			if(list.size()>0) {
				sum+=list.get(0);
				list.remove(0);
			}
		}

		out.println(sum);
	}

	//二部探索
	static int Search(List<Integer> list, int k, int Search_l) {
		int l = Search_l;
		int r = list.size();
		while(r - l > 1) {
			int mid = (r + l) / 2;
			if(list.get(mid) <= k) r = mid;
			else l = mid;
		}
		return r;
	}


	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

}
//  [java]
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int M = nextInt();

		int[][] AB = new int[N][2];
		for(int i=0;i<N;i++) {
			AB[i] = nextIntArray(2);
		}
		Arrays.sort(AB,(a1,a2)->Integer.compare(a2[1],a1[1]));
		Arrays.sort(AB,(a1,a2)->Integer.compare(a1[0],a2[0]));

		List<Integer> list = new ArrayList<Integer>(N);
		long sum = 0;
		int AB_i = 0;
		for(int l=1;l<=M;l++) {
			int Search_l = -1;
			while(AB_i<N&&AB[AB_i][0]==l) {
				int Insert_i = Search(list ,AB[AB_i][1],Search_l);
				if(M<Insert_i)break;// 候補外となるため挿入する必要なし
				list.add(Insert_i,AB[AB_i][1]);
				AB_i++;
				Search_l = Insert_i;
			}

			if(list.size()>0) {
				sum+=list.get(0);
				list.remove(0);
			}
		}

		out.println(sum);
	}

	//二部探索
	static int Search(List<Integer> list, int k, int Search_l) {
		int l = Search_l;
		int r = list.size();
		while(r - l > 1) {
			int mid = (r + l) / 2;
			if(list.get(mid) <= k) r = mid;
			else l = mid;
		}
		return r;
	}


	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define YN(y, n, b) (b? y : n)
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N, M;
    cin >> N >> M;
    priority_queue<pair<i32, i32>, Vec<pair<i32, i32>> > q;
    for (i32 i = 0; i < N; i++) {
        i32 A, B;
        cin >> A >> B;
        q.push(make_pair(B, A));
    }
    Vec<i32> D(M + 1, 0);
    while (!q.empty()) {
        pair<i32, i32> c = q.top();
        q.pop();
        while (c.second > M && !q.empty()) {
            c = q.top();
            q.pop();
        }
        if (c.second > M) break;
        for (i32 j = c.second; j <= M; j++) {
            if (D[j] == 0) {
                D[j] = c.first;
                break;
            }
        }
        if (q.empty()) break;
    }
    i32 sum = 0;
    for (i32 i = 0; i <= M; i++) sum += D[i];
    cout << sum << endl;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)

typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<long long int> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvll;

int main() {
  int n, m;
  cin >> n >> m;

  map<int, vector<int>> jobs;

  for(int i=0;i<n;i++) {
    int a, b;
    cin >> a >> b;
    jobs[a].emplace_back(b);
  }

  auto it = jobs.begin();
  long long int ans = 0;
  vector<int> jobsPool(0);

  for(int i=1;i<=m;i++) {
    if(it!=jobs.end() && it->first == i) {
      jobsPool.insert(jobsPool.end(), (it->second).begin(), (it->second).end());
      sort(jobsPool.begin(), jobsPool.end());
      it++;
    }

    if(jobsPool.empty()) continue;
    else {
      ans += jobsPool.back();jobsPool.pop_back();
    }
  }

  cout << ans << endl;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long int i=0;i<(n);++i)
typedef long long int ll;

int main(){

    int n,m;
    cin >> n >> m;
    vector<vector<int>> a(1e+5+1);
    ll ans=0L;
    rep(i,n){
        int aa,b;
        cin >> aa >> b;
        a[aa].push_back(b);
    }
    vector<int> bb;
    for(int i=1;i<=m;i++){
        if(a[i].size()!=0) {
            rep(j, a[i].size()) {
                bb.push_back(a[i][j]);
            }
            sort(bb.begin(),bb.end());
        }
        if(bb.size()!=0){
            ans+=bb.back();
            bb.pop_back();
        }
    }
//    rep(i,bb.size()){
//        cout << bb[i] << endl;
//    }
    cout << ans << endl;

    return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#define MAX 100001

int list[MAX][2];

int compare(void *a, void *b){
  if(((int*)a)[0] == ((int*)b)[0]){
    return ((int*)b)[1] - ((int*)a)[1];
  }else{
    return ((int*)a)[0] - ((int*)b)[0];
  }
}

int main(){
  int n,m,lead[MAX],
      index,*ago,start,p,
      i,j,sum=0;
  
  scanf("%d%d", &n, &m);
  for(i=0;i<n;i++){
    scanf("%d%d", &list[i][0], &list[i][1]);
  }
  
  qsort(list, n, sizeof(int) * 2, compare);
  
  if(list[0][0] > m){
    printf("0");
    return 0;
  }
  p = 0;
  
  i=1;
  j=0;
  while(1){
    start = j;
    i = list[j][0];
    while(i == list[j][0]){
      j++;
      if(j==n)break;
    }
    if(j==n)break;
    if(list[j][0] > m)break;
    lead[start] = j;
  }
  lead[start] = -1;
  
  for(i=1;i<=m;i++){
    if(list[p][0] > i)continue;
    ago = &p;
    index = p;
    j = p;
    while(lead[j] != -1){
      if(list[lead[j]][0] > i)break;
      if(list[lead[j]][1] > list[index][1]){
        index = lead[j];
        ago = &lead[j];
      }
      j = lead[j];
    }
    sum += list[index][1];
    if(index+1 == n){
      *ago = -1;
    }else if(list[index+1][0] == list[index][0]){
      *ago += 1;
      lead[index+1] = lead[index];
    }else{
      *ago = lead[index];
    }
    if(p == -1)break;
  }
      
  printf("%d", sum);
  
  return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>

typedef struct parttime{
  int day;
  int money;
}pt;

int cmp_day(const void *x, const void *y) {
  int xd = ((pt *)x)->day, yd = ((pt *)y)->day;
  if (xd == yd) return ((pt *)y)->money - ((pt *)x)->money;
  return xd - yd;
}

void msort(pt *A, pt *B, int left, int right) {
  if (left != 0) {
    int i=0, j=left, k=0;
    while (i<left && j<right+left) {
      if (A[i].money > A[j].money) {
        B[k++] = A[i++];
      } else {
        B[k++] = A[j++];
      }
    }
    if (i == left) {
    while (j < right+left) {
        B[k++] = A[j++];
      }
    } else {
      while (i < left) {
        B[k++] = A[i++];
      }
    }
    for (int l = 0; l < k; l++) {
      A[l] = B[l];
    }
  }
}

int main() {
  int n, m, ans = 0;
  scanf("%d%d", &n, &m);
  pt c[n], b[n]; int d[100001];
  for (size_t i = 0; i < n; i++) {
    scanf("%d%d", &(c+i)->day, &(c+i)->money);
  }
  qsort(c, n, sizeof(pt), cmp_day);
  for (int i=0; i<m+1; i++) d[i] = 0;
  for (int i=0; i<n; i++) {
    if (c[i].day > m) break;
    d[c[i].day] = i+1;
  }
  for (int i=1; i<m+1; i++) if (d[i] == 0) d[i] = d[i-1];
  int j=0;
  for (int i=1; i<m+1; i++) {
    if (j>=d[i]) continue;
    if (d[i] != d[i-1]) msort(c+j, b, d[i-1]-j, d[i]-d[i-1]);
    ans += c[j].money;
    j++;
  }
  printf("%d\n", ans);
  return 0;
}