from functools import lru_cache @lru_cache(maxsize=10**6) def solve(N,K): if N==1: if K==0: return 0 else: return 2 return solve(N-1,K)+solve(N-1,K//N) N,K=map(int,input().split()) print(solve(N,K)-1)