n,k=map(int,input().split()) if n>9*18: print(k) exit() k+=1 dp=[[[0]*10 for _ in range(n+1)]] dp[0][0][0]=1 while True: now=[[0]*10 for _ in range(n+1)] p=0 for i in range(n+1): s=sum(dp[-1][i]) for j in range(10): if i+j<=n: now[i+j][j]+=s p+=s dp.append(now) if p>=k: break ans=[] ma=n while dp: now=dp.pop() for i in range(10): p=0 for j in range(ma+1): p+=now[j][i] if k>p: k-=p else: ma-=i ans.append(str(i)) break ans.pop() print(''.join(ans))