import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n,s = map(int, input().split()) g = [1] v = 1 for i in range(1,s+2): v *= i g.append(v) def ps(n,v): """長さnの順列で、辞書順v番目 """ seen = [False]*n ans = [] for i in range(n): num = v//g[n-i-1] count = 0 for j in range(n): if seen[j]: continue if count==num: break if not seen[j]: count += 1 ans.append(j) seen[j] = True v = v%g[n-i-1] return ans def index(ps): """順列psの辞書順 """ n = len(ps) v = 0 seen = [False] * n for i in range(n): num = 0 for j in range(ps[i]): if not seen[j]: num += 1 v += num * g[n-i-1] seen[ps[i]] = True return v p = ps(s,n) pp = [None]*s for i,v in enumerate(p): pp[v] = i print(index(pp))