import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
public class EarnMaxScore {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// while(sc.hasNextLine()){
int count = Integer.parseInt(sc.nextLine());
int target = Integer.parseInt(sc.nextLine());
HashMap<Integer,List<Integer>> map = new HashMap<>();
for(int i=0;i<count;i++){
String[] split = sc.nextLine().split("\\s+");
int time = Integer.parseInt(split[0]);
int score =Integer.parseInt(split[1]);
if(map.containsKey(time)){
map.get(time).add(score);
}else{
List<Integer> list = new ArrayList<>();
list.add(score);
map.put(time,list);
}
}
AtomicInteger sum = new AtomicInteger();
map.entrySet().stream().filter(e->e.getKey()<=target)
.sorted((e1,e2)->{return e1.getKey()-e2.getKey();})
.forEach(entry->{
List<Integer> collect = entry.getValue().stream().sorted((e1, e2) -> {
return e2 - e1;
}).collect(Collectors.toList());
sum.addAndGet(collect.get(0));
});
System.out.println(sum.get());
// }
}
}