Harryxun/stf_run huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld  = long double;
using pll = pair<ll, ll> ;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=1LL<<60 ;
const ll MOD=1e9+7 ;
const ld PI=acos(-1);
const ld EPS = 1e-9; //微調整用（EPSより小さいと0と判定など）

#define gcd __gcd //llは受け取ってくれない
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define ALL(a) a.begin(),a.end() //sort(ALL(vec));
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define PB push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

//最大値、最小値を更新する。aよりbのが大きい（小さい）か等しければaを更新してtrueを返す。そうでなければ何もせずfalseを返す chmax(nowmax,x);
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

// ----- template end ---- //

// ------- library ------- //


// ----- library end ----- //



int main() {
  string N;
  ll K;
  cin >> N >> K;

  set<char> NOs;
  rep(i,K){
    char a;
    cin >> a;
    NOs.insert(a);
  }

  bool ansflag = false; //答えが見つかったら1
  int ans = 0;
  REP(i, stoi(N), 100000){
    ansflag = true; //一旦1にする
    for (char c : to_string(i)){
      if (NOs.find(c) != NOs.end()){ //もしcがNOsに入っていたら(ダメな数字を使っていたら)
        ansflag = false;
      }
    }
    if (ansflag){
      ans = i;
      break;
    }
  }

  cout << ans << endl;



}


 

### FIXED CODE ###

###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

N, M = mi()
nos = set(input().split())
#昇順ソート
availables = sorted(list(set(map(str, (0,1,2,3,4,5,6,7,8,9))) - nos))

#方針
#桁数が変われば、(1)0が使える場合は、使える一番低い数字+あとは全部0
#              (2)0が使えない場合は、使える一番低い数字で埋めるだけ
#とはいえ、元々が3桁とかなら全探索で十分
#5桁になると怪しいので、(1)(2)を活かす

#まずは9999までの間に答えがあるかどうか
#N=9999でも、9が嫌いじゃない場合があるから探索する
ans = 0
for i in range(N, 10000):
  if not (set(str(i)) & nos): #使えない(nos)のに使ってる(set内)が無かったら
    ans = i
    break
if ans == 0:
  #もしここまでで答えが出ていなかったら
  if '0' in availables:
    print(str(list(availables)[1])+str(list(availables)[0])*4)
    exit()
  else:
    print(str(list(availables)[0])*5)
    exit()

print(ans)
n,m = map(int,input().split())
alis = list(map(int,input().split()))
lis = [list(map(int,input().split())) for x in range(m)]
clis = [[x[1]]*x[0] for x in lis]
clis = [x for y in clis for x in y]
clis.sort(reverse=True)
alis.sort()
for x,y in zip(alis,clis):
    if x>=y:
        ans += x
    else:
        ans += y
if len(clis) < len(alis):
    ans__ = sum(alis[len(clis):])
    ans += ans__
    print(ans)
else:
    print(ans)


### FIXED CODE ###

n,m = map(int,input().split())
alis = list(map(int,input().split()))
lis = [list(map(int,input().split())) for x in range(m)]
for x in alis:
    lis.append([1,x])
lis.sort(reverse=True,key=lambda x:x[1])
ans = 0
for x in lis:
    (number,point) = x
    if number >= n:
        number = n
        ans += number * point
        #print(n)
        #print(ans,'+=',number,'*',point)
        break
    ans += number * point
    n -= number
    #print(n)
    #print(ans,'+=',number,'*',point)
print(ans)
#print(lis)
x = int(input()).split()
a = int(x[0])
b = int(x[1])

if a < b:
  print('a < b')
elif a == b:
  print('a == b')
else:
  print('a > b')

### FIXED CODE ###

x = input().split()
i = list(map(int,x))
a = i[0]
b = i[1]

if a > b:
  print('a > b')
elif a == b:
  print('a == b')
else:
  print('a < b')
import sys
for l in sys.stdin:
    a.append(l)

a_array = a[1].split(' ')

sum = 0

for i in a_array:
    sum += (1 / int(i))

print(1 / sum)

### FIXED CODE ###

import sys
a = []
for l in sys.stdin:
    a.append(l)

a_array = a[1].split(' ')
a_array

sum = 0

for i in a_array:
    sum += (1 / int(i))

print(1 / sum)
A, B, K = map(int,input().rstrip().split())
 
for i in range(K):
	if i % 2 == 0:
		B = B + A/2
		A = A/2
	else:
		A = A + B/2
        B = B/2 
print ('{} {}'.format(A,B))


### FIXED CODE ###

A, B, K = map(int, input().split())
for i in range(0, K):
    if(i & 1):
        if(B & 1):
            B -= 1
        A += B//2
        B //= 2
    else:
        if(A & 1):
            A -= 1
        B += A//2
        A //= 2
print("{0} {1}".format(A, B))
A, B = map(input().split())

A = int(A)
B = float(B)

print(int((A * (B * 100)) / 100)) 

### FIXED CODE ###

A, B = input().split()

A = int(A)
B = int(float(B) * 100 + 0.5)
ans = A * B // 100

print(ans)
a, b = map(int,inptu().split())
r = []
r.append(a+b)
r.append(a-b)
r.append(a*b)
print(max(r))


### FIXED CODE ###

a, b = map(int,input().split())
r = []
r.append(a+b)
r.append(a-b)
r.append(a*b)
print(max(r))
a, b = map(int, input().split())
 
if a > b:
  print(a+a-1)
elif a < b:
  print(b+b-1)
else
  print(a+b)

### FIXED CODE ###


a, b = map(int, input().split())
 
if a > b:
    print(a+a-1)
elif a < b:
    print(b+b-1)
else:
    print(a+b)
K,X=map(int,input().split())
if 500*K>=X
	print("Yes")
  else
  	print("No")

### FIXED CODE ###

K,X=map(int,input().split())
if 500*K>=X:
	print("Yes")
else:
  	print("No")
from collections import Counter


N = int(input())
lstA = list(map(int, input().split()))
mod = 10**9 + 7
countA = Counter(lstA)


if N % 2:
    if countA[0] == 1 and all(countA[i] == 2 for i in range(2, N, 2)):
        ans = 2 ** (N // 2) % mod
    else:
        ans = 0
else:
    if all(countA[i] == 2 for i in range(1, N, 2)):
        ans = 2 ** (N // 2) % mod

print(ans)

### FIXED CODE ###

from collections import Counter


N = int(input())
lstA = list(map(int, input().split()))
mod = 10**9 + 7
countA = Counter(lstA)
ans = 0

if N % 2:
    if countA[0] == 1 and all(countA[i] == 2 for i in range(2, N, 2)):
        ans = pow(2, N//2, mod)
else:
    if all(countA[i] == 2 for i in range(1, N, 2)):
        ans = pow(2, N//2, mod)


print(ans)
import math
from functools import reduce
n = map(int, input().split())
x = list(map(int, input().split()))
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
print(gcd_list(x))

### FIXED CODE ###

import math
n = int(input())
l = [int(i) for i in input().split()]

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義
s = gcd(l[0],l[1])
for i in l:
    s = gcd(s,i)
   

print(s)
r = int(input())

print({0}.format(r^2))

### FIXED CODE ###


r = int(input())

r2 = int(r**2)

print(r2)
n=[int(i) for i in input().split()]
array=[]
abs_array=[]
for i in range(n[0]):
  array.append(n[1]+i-1)
  abs_array.append(abs(n[1]+i-1))
abs_array=abs_array.sort()
if(abs_array[0] in array == True):
  print(sum(array)-abs_array[0])
else:
  print(sum(array)+abs_array[0])

### FIXED CODE ###

n=[int(i) for i in input().split()]
array=[]
abs_array=[]
for i in range(1,n[0]+1):
  array.append(n[1]+i-1)
  abs_array.append(abs(n[1]+i-1))
abs_array.sort()
if abs_array[0] in array :
  print(sum(array)-abs_array[0])
else:
  print(sum(array)+abs_array[0])
a,b,c = map(int, input().split())

if a < b < c:
    result = "Yes"

else:
    result = "No"

print(result)



### FIXED CODE ###

count = 0
a = 0
b = 0
while (count <= 3000) and (a  <= 10000) and (b <= 10000):
    a,b = map(int, input().split())
    if a == b == 0:
        break

    if a > b:
        tmp = a
        a = b
        b = tmp

    count += 1
    print(a, b, sep = ' ')
#!venv/bin/python
 
import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

N, M = [ int(x) for x in input().split() ]
A = [ int(x) for x in input().split() ]
BC = []
for _i in range(M):
    BC.append([ int(x) for x in input().split() ])
A = sorted(A)
BC = sorted(BC, key = lambda x: x[1], reverse = True)

p = 0

def solve():
    global A, BC, p
    for bc in BC:
        for _i in range(bc[0]):
            if A[p] < bc[1]:
                A[p] = bc[1]
                p += 1
            else:
                return

solve()
print(sum(A))



### FIXED CODE ###

#!venv/bin/python
 
import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

N, M = [ int(x) for x in input().split() ]
A = [ int(x) for x in input().split() ]
BC = []
for _i in range(M):
    BC.append([ int(x) for x in input().split() ])
A = sorted(A)
BC = sorted(BC, key = lambda x: x[1], reverse = True)

p = 0

def solve():
    global A, BC, p
    for bc in BC:
        for _i in range(bc[0]):
            if p >= len(A):
                return
            if A[p] < bc[1]:
                A[p] = bc[1]
                p += 1
            else:
                return

solve()
print(sum(A))
from functools import reduce
from operators import mul

n = int(input())
a = list(map(int, input().strip()))

m = reduce(mul, a) - 1
ans = 0
for ai in a:
  ans += mul % ai

print(ans)


### FIXED CODE ###

from functools import reduce
from operator import mul
n = int(input())
a = list(map(int, input().split()))

m = reduce(mul, a) - 1
ans = 0
for ai in a:
    ans += m % ai
print(ans)
*a = map(int,input().split())
print(max(a)-min(a))

### FIXED CODE ###

a,b,c = sorted(map(int,input().split()))
print(c-b + b-a)
n = input()
tmp = int(n[-3])
if tmp==0:
    print(0)
else:
    print((10-tmp)*100)

### FIXED CODE ###

n = int(input())
tmp = 10000-n
s = tmp%1000

print(s)
import math
import numpy as np
import re


def inputs(): return [int(s) for s in input().split()]


def main():
    s = input()
    cnt = 0
    s = s.replace('A', '1').replace('BC', '0')
    arr = re.split('[A-C]', s)
    arr = [list(x) for x in arr]
    flag = True
    while flag:
        flag = False
        for a in arr:
            tmp = 0
            for i in a:
                tmp += i
                if i is 0:
                    cnt += tmp
                    
    return cnt


if __name__ == '__main__':
    print(main())


### FIXED CODE ###

import math
import numpy as np
import re


def inputs(): return [int(s) for s in input().split()]


def main():
    s = input()
    cnt = 0
    s = s.replace('A', '1').replace('BC', '0')
    arr = re.split('[A-C]', s)
    arr = [list(x) for x in arr]
    flag = True
    while flag:
        flag = False
        for a in arr:
            tmp = 0
            for i in a:
                i = int(i)
                tmp += i
                if i is 0:
                    cnt += tmp

    return cnt


if __name__ == '__main__':
    print(main())
a=int(input())
b=int(input())
print(a*b)

### FIXED CODE ###

a,b= map(int, input().split())
print(a*b)
(h, w) = map(int, input().split(" "))

a=[]
for i in range(h):
        a.append(input())

print("#" * (w+2))

for i in range(h):
    print("#"+a+"#")

print("#" * (w+2))



### FIXED CODE ###

(h, w) = map(int, input().split(" "))

a=[]
for i in range(h):
        a.append(input())

print("#" * (w+2))

for i in range(h):
    print("#"+a[i]+"#")

print("#" * (w+2))
n, m = map(int, input().split())
a = list(int(input()) for _ in range(m))

for i in range(m):
    if a[i+1] - a[i] == 1:
        print(0)
        exit()

dp = [0] * (n+1)
dp[0] = 1

if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2, n+1):
    if i in a:
        continue
    dp[i] = dp[i-1] + dp[i - 2]
    dp[i] %= 1000000007

print(dp[n])




### FIXED CODE ###

n, m = map(int, input().split())
a = set([int(input()) for _ in range(m)])

dp = [0] * (n+1)
dp[0] = 1

if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2, n+1):
    if i in a:
        continue
    dp[i] = dp[i-1] + dp[i - 2]
    dp[i] %= 1000000007

print(dp[n])
import math
A,B = map(int,input().split())
print(int((A*B)/math.gcd(A,B)))

### FIXED CODE ###

import fractions
A,B = map(int,input().split())
print((A*B)//fractions.gcd(A,B))
H, W = (int(i) for i in input().split())
t = []
t.append(['.']*(H+2))

for j in range(H):
	tmp = input()
	tmp = '.' + tmp + '.'
	t.append(list(tmp))

t.append(['.']*(H+2))


def issharp(block):
	if block == '#':
		return True
	else: return False

def CheckBlock(i,k):
#   0
# 1 X 2
#   3
	if t[i][k-1] == '#': #check up
		return 0
	elif t[i-1][k] == '#': #check left
		return 1
	elif t[i+1][k] == '#': #check right
		return 2
	elif t[i][k+1] == '#': #check down
		return 3
	else:
		return 4

for i in range(1,W+1):
	for k in range(1,H+1):
		if issharp(t[i][k]) == True:
			marker = CheckBlock(i,k)
			if marker == 4:
				print('No')
				quit()
print('Yes')

### FIXED CODE ###

H, W = (int(i) for i in input().split())
t = []
t.append(['.']*(H+2))

for j in range(H):
	tmp = input()
	tmp = '.' + tmp + '.'
	t.append(list(tmp))

t.append(['.']*(H+2))

def CheckBlock(i,k):
	if t[i][k-1] == '#': #check up
		return 0
	elif t[i-1][k] == '#': #check left
		return 1
	elif t[i+1][k] == '#': #check right
		return 2
	elif t[i][k+1] == '#': #check down
		return 3
	else:
		return 4

for k in range(1,W+1):
	for i in range(1,H+1):
		if t[i][k] == '#':
			marker = CheckBlock(i,k)
			if marker == 4:
				print('No')
				quit()
print('Yes')
s = input()
K = int(input())
n = len(s)
t = s[::-1]
if 2*K+1 >= n:
  print(n)
  exit()
dp = [[[0 for i in range(K+1)] for j in range(n+1)] for k in range(n+1)]

ans = min(2*K+1,n)
flg2 = 0
for center in range(1,n-1):
  flg = 0
  sf = s[:center]
  sl = t[:n-center-1]
  if s[center] == s[center+1]:
    flg = 1
  sfl = len(sf)
  sll = len(sl)
  for j in range(1,sll+1):
    dp[sfl][j][0] = max(dp[sfl-1][j][0],dp[sfl][j-1][0])
    if sf[-1] != sl[j-1]:
      for k in range(1,K+1):
        dp[sfl][j][k] = max(dp[sfl-1][j-1][k-1]+1,dp[sfl-1][j][k],dp[sfl][j-1][k])
    if sf[-1] == sl[j-1]:
      dp[sfl][j][0] = max(dp[sfl][j][0],dp[sfl-1][j-1][0]+1)
      for k in range(1,K+1):
        dp[sfl][j][k] = max(dp[sfl-1][j-1][k-1]+1,dp[sfl-1][j-1][k]+1,dp[sfl-1][j][k],dp[sfl][j-1][k])
  if ans < max(dp[sfl][sll][K]*2+1,dp[sfl][sll-1][K]*2+1+flg):
    flg2 = flg
  ans= max(dp[sfl][sll][K]*2+1,dp[sfl][sll-1][K]*2+1+flg,ans)
if flg2 == 1:
  print(2/0)
print(ans)

### FIXED CODE ###

s = input()
K = int(input())
n = len(s)
t = s[::-1]
if 2*K+1 >= n:
  print(n)
  exit()
dp = [[[0 for i in range(K+1)] for j in range(n+1)] for k in range(n+1)]
if n == 2 and K == 0:
  if s == t:
    print(2)
    exit()
  else:
    print(1)
    exit()
ans = min(2*K+1,n)
for center in range(1,n-1):
  flg = 0
  sf = s[:center]
  sl = t[:n-center-1]
  if s[center] == s[center+1]:
    flg = 1
  sfl = len(sf)
  sll = len(sl)
  for j in range(1,sll+1):
    dp[sfl][j][0] = max(dp[sfl-1][j][0],dp[sfl][j-1][0])
    if sf[-1] != sl[j-1]:
      for k in range(1,K+1):
        dp[sfl][j][k] = max(dp[sfl-1][j-1][k-1]+1,dp[sfl-1][j][k],dp[sfl][j-1][k])
    if sf[-1] == sl[j-1]:
      dp[sfl][j][0] = max(dp[sfl][j][0],dp[sfl-1][j-1][0]+1)
      for k in range(1,K+1):
        dp[sfl][j][k] = max(dp[sfl-1][j-1][k-1]+1,dp[sfl-1][j-1][k]+1,dp[sfl-1][j][k],dp[sfl][j-1][k])
  if flg:
    ans= max(dp[sfl][sll][K]*2+1,dp[sfl][sll-1][K]*2+2,ans)
  elif K > 0:
    ans= max(dp[sfl][sll][K]*2+1,dp[sfl][sll-1][K-1]*2+2,ans)
  else:
    ans= max(dp[sfl][sll][K]*2+1,ans)
print(ans)
import math
a, b = map(int, input().split())
num = a*b
print('{:.0f}'.format(num))

### FIXED CODE ###

def resolve():
    A, B = input().split()
    ans = int(A)*int(B[0])*100+int(A)*int(B[2:])
    print(str(ans)[:-2] if len(str(ans)) >= 3 else "0")
resolve()
s = input()
q_number = int(input())
reverse_flag = 1
for i in range(q_number):
  temp = input().split()
  if temp[0] == "1": 
    reverse_flag = reverse_flag * -1
  else:
    if int(temp[1]) == 1 or -2:
      s = temp[2] + s
    elif int(temp[1]) == -1 or 2:
      s = s + temp[2]      

if reverse_flag = -1:
  s = s[::-1]
  
print(s)

### FIXED CODE ###

s = input()
q_number = int(input())
reverse_flag = 1
head = ""
tail = ""
for i in range(q_number):
  temp = input().split()
  if temp[0] == "1": 
    reverse_flag = reverse_flag * -1
  else:
    headstails = int(temp[1])*reverse_flag 
    if headstails == 1 or headstails == -2:
      head = temp[2] + head
    else:
      tail = tail + temp[2]
      
if reverse_flag == 1:
  print(head+s+tail)
else:
  print(tail[::-1]+s[::-1]+head[::-1])
a, b = map(int, input().split())
if a * b % 2 == 0:
  print(Even)
else:
  print(Odd)

### FIXED CODE ###

a, b = map(int, input().split())
if a * b % 2 == 0:
  print("Even")
else:
  print("Odd")
n, m ,k = map(int,input().split())
a_list = [int(a) for a in input().split()]
b_list = [int(b) for b in input().split()]
time = 0
a_num = 0
b_num = 0
count = 0

# 次回が小さい方を選択する
while True:
    
    if (len(a_list) < a_num + 1) and (len(b_list) < b_num + 1): 
        break

    elif  (len(a_list) < a_num + 1) and(len(b_list) >= b_num + 1):
        time += b_list[b_num]      
        b_num += 1
     
    elif (len(a_list) >= a_num + 1) and (len(b_list) < b_num + 1):
        time += a_list[a_num]      
        a_num += 1
        
    else:
        if sum(a_list[a_num:]) < sum(b_list[b_num:]):
            time += a_list[a_num]
            a_num += 1
        else:
            time += b_list[b_num]      
            b_num += 1
    
    if time <= k:
        count += 1
    else:
        break

print(count)

### FIXED CODE ###

a = int(input())

print(a+a*a+a*a*a)
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
def tr(x):
    if "DEBUG" in globals(): sys.stderr.write(f"{x}\n")

x = ni()
if x == 1:
    print("Hello World")
else:
    a = ni()
    b = ni()
    print(a+b)
    

### FIXED CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

x = ni()
if x == 1:
    print("Hello World")
else:
    a = ni()
    b = ni()
    print(a+b)
N = int(input())
S = list(input())
Sum = 0
for k in range(3,N+1):
    for j in range(2,k):
        for i in range(1,j):
            if abs(j - i) != abs(k - j):
                if S[i-1] != S[j-1] and S[j-1] != S[k-1] and S[k-1] != S[i-1]:
                  Sum += 1
print(Sum)

### FIXED CODE ###

N = list(input())
if '7' in N:
    print('Yes')
else:
    print('No')
a=int(input())
b=list(map(int,input().split()))
b.sort(reverse=True)
if a%2==0:
  print(sum(b[:a//2-1]*2-b[0]))
else:
  print(sum(b[:a//2+1]*2-b[0]-b[a//2])

### FIXED CODE ###

a=int(input())
b=list(map(int,input().split()))
b.sort(reverse=True)
ans=0
for i in range(a-1):
  i=(i+1)//2
  ans+=b[i]
print(ans)
#input = raw_input
import numpy as np

N, M = map(int, input().split())

pairs = []
for i in range(N):
    A, B = map(int, input().split())
    if M >= A:
        pairs.append([A, B])

pairs = sorted(pairs, key=lambda elm: -elm[1])
#print(pairs)

out = 0

#not_done = [True for _ in range(M)]

#counts = [0 for _ in range(M)]
cumsum_counts = np.zeros(M, dtype=int)

all_sum = 0

ue_end_i = M-1
for A, B in pairs:
    ue_start_i = M-A+1
    if ue_start_i <= ue_end_i:
        ue_limit = ue_end_i - ue_start_i + 1
        #ue_sum = sum(counts[ue_start_i:])
        ue_sum = cumsum_counts[ue_start_i]
        hamidashi = max(ue_sum - ue_limit, 0)
    else:
        # ue_start_i == M
        hamidashi = 0
    #print("hamidashi", hamidashi)

    cur_limit = M- A + 1 - hamidashi # 0 ~ M-A
    sudeni = all_sum - ue_sum
    aki = cur_limit - sudeni

    if aki >= 1:
        out += B
        #counts[M-A] += 1
        cumsum_counts[M-A:] += 1
        all_sum += 1

print(out)

### FIXED CODE ###

#input = raw_input
#import numpy as np

from heapq import heappush, heappop

N, M = map(int, input().split())

values = [[] for i in range(M+1)]
for i in range(N):
    A, B = map(int, input().split())
    if M >= A:
        values[A].append(-B)

#print(values)
out = 0
elms = []
for i in range(1, M+1):
    #print("values[i]", values[i])
    for elm in values[i]:
        heappush(elms, elm)
        
    if len(elms) >= 1:
        max_val = - heappop(elms)
        #print("mval", max_val)
        out += max_val

print(out)
%%time
import numpy as np

mod=10**9+7
#s=input()
s="?"*10**5


p=[[i*j%13 for i in range(10)] for j in range(13)]
rev=reversed(s)
d=np.array([0 for i in range(13)])
d[0]=1
keep=np.array([0 for _ in range(13)])
mul=1
cal=0
t=np.array([i for i in range(13)])
for v in rev:
    if v!="?":
        cal+=mul*int(v)%13
    else:
        t_d=keep.copy()
        for j in range(1,10):
            t_d[(t+mul*j)%13]+=d
        d+=t_d
        d%=mod
        
    mul*=10
    mul%=13

cal%=13
if cal<=5:
    cal=5-cal
else:
    cal=18-cal
print(d[cal]%mod)
#print(d)
#h=d
#print([i%mod for i in h])



### FIXED CODE ###

#%%time
mod=10**9+7
s=input()


#p=[[i*j%13 for i in range(10)] for j in range(13)]
rev=reversed(s)
d=[0 for i in range(13)]
d[0]=1
keep=[0 for _ in range(13)]
mul=1
cal=0
for v in rev:
    #print(i+num+1)
    if v=="?":
        t_d=[0 for _ in range(13)]
        #print("i,tmp:",i+num+1,",",tmp)
        for k in range(0,13):
            for j in range(0,10):
                t_d[(mul*j+k)%13]+=d[k]
            t_d[k]%=mod
        d=t_d
    else:
        cal+=mul*int(v)%13
    mul*=10
    mul%=13
        #print(t_d)
cal%=13
if cal<=5:
    cal=5-cal
else:
    cal=18-cal
print(d[cal]%mod)
#print(d)
#h=d
#print([i%mod for i in h])
s = input()
flag = True
while s:
    if s[0:5] == "dream":
        s = s[5:]
        if s[0:2] == "er":
            if s[0:5] != "erase":
                s = s[2:]
    elif s[0:5] == "erase":
        s = s[5:]
        if s[0] == "r":
            if s[0:5] != "erase":
                s = s[1:]
    else:
        flag = False
        break
if flag == True:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

s = input()
flag = True
while s:
    if s[0:5] == "dream":
        s = s[5:]
        if s[0:2] == "er":
            if s[0:5] != "erase":
                s = s[2:]
    elif s[0:5] == "erase":
        s = s[5:]
        if s[0:1] == "r":
            if s[0:5] != "erase":
                s = s[1:]
    else:
        flag = False
        break
if flag == True:
    print("YES")
else:
    print("NO")
A = int(input())
B = int(input())
if A>12:
    print(B)
elif 13>A>5:
    print(B//2)
else:
    print(0)

### FIXED CODE ###

a,b = map(int,input().split());print(b//-~(a<13)*(a>5))
n,k = map(int,input().split())

pi = 0
for i in range(1,n+1):
  need = math.ceil(math.log(k/i,2))  
  if need > 0:
    pi += (1/2) ** need
  else :
    pi +=1      
print(pi/n)    

### FIXED CODE ###

import math
n,k = map(int,input().split())
 
pi = 0
for i in range(1,n+1):
  need = math.ceil(math.log(k/i,2))  
  if need > 0:
    pi += (1/2) ** need
  else :
    pi +=1      
print(pi/n)
A, B, K = map(int, input())
S = sorted(set(list(range(A, B+1)[:K]) + list(range(A, B+1)[-K:])))
print(*S, sep="\n")


### FIXED CODE ###

A, B, K = map(int, input().split())
S = sorted(set(list(range(A, B+1)[:K]) + list(range(A, B+1)[-K:])))
print(*S, sep="\n")
NM = NM.split()
N = int(NM[0])
M = int(NM[1])

AB = {}
for i in range(N):
  temp = input()
  temp = temp.split()
  AB[int(temp[0])] = int(temp[1])

A_list = list(AB.keys())
A_list.sort()

cost = 0
amount = 0
for i in range(N):
  if amount + AB[A_list[i]] <= M:
    amount += AB[A_list[i]]
    cost += A_list[i]*AB[A_list[i]]
  else:
    print(amount)
    temp = M - amount
    cost += A_list[i]*temp
    break
    
print(cost)

### FIXED CODE ###

from sys import stdin
import heapq
hq = []  

NM = input()
NM = NM.split()
N = int(NM[0])
M = int(NM[1])

hq = []
AB = {}
for i in range(N):
  temp = input()
  temp = temp.split()
  AB[int(temp[0])] = int(temp[1])
  heapq.heappush(hq, (int(temp[0]), int(temp[1])))

cost = 0
amount = 0
for i in range(N):
  temp = heapq.heappop(hq)
  if amount + temp[1] < M:
    amount += temp[1]
    cost += temp[0]*temp[1]
  else:
    temp1 = M - amount
    cost += temp[0]*temp1
    break
    
print(cost)