""" """ N,K = map(int,input().split()) K -= 1 Nlis = list(str(N)) Nlis.reverse() ans = [] dig = 1 for c in Nlis: dig *= int(c)+1 ans.append( K % dig ) K //= dig ans.reverse() print (int( "".join(map(str,ans)) ))